spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aarondav <...@git.apache.org>
Subject [GitHub] spark pull request: SPARK-1305: Support persisting RDD's directly ...
Date Wed, 02 Apr 2014 07:51:59 GMT
Github user aarondav commented on a diff in the pull request:

    https://github.com/apache/spark/pull/158#discussion_r11195342
  
    --- Diff: core/src/main/scala/org/apache/spark/storage/TachyonStore.scala ---
    @@ -0,0 +1,143 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.storage
    +
    +import java.io.IOException
    +import java.nio.ByteBuffer
    +
    +import scala.collection.mutable.ArrayBuffer
    +
    +import tachyon.client.{WriteType, ReadType}
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.util.Utils
    +import org.apache.spark.serializer.Serializer
    +
    +
    +private class Entry(val size: Long)
    +
    +
    +/**
    + * Stores BlockManager blocks on Tachyon.
    + */
    +private class TachyonStore(
    +    blockManager: BlockManager,
    +    tachyonManager: TachyonBlockManager)
    +  extends BlockStore(blockManager: BlockManager) with Logging {
    +
    +  logInfo("TachyonStore started")
    +
    +  override def getSize(blockId: BlockId): Long = {
    +    tachyonManager.getFile(blockId.name).length
    +//    tachyonManager.getBlockLocation(blockId).length
    +  }
    +
    +  override def putBytes(blockId: BlockId, _bytes: ByteBuffer, level: StorageLevel): PutResult
=  {
    +    putToTachyonStore(blockId, _bytes, true)
    +  }
    +
    +  override def putValues(
    +    blockId: BlockId,
    +    values: ArrayBuffer[Any],
    +    level: StorageLevel,
    +    returnValues: Boolean): PutResult = {
    +    return putValues(blockId, values.toIterator, level, returnValues)
    +  }
    +
    +  override def putValues(
    +    blockId: BlockId,
    +    values: Iterator[Any],
    +    level: StorageLevel,
    +    returnValues: Boolean): PutResult = {
    +    logDebug("Attempting to write values for block " + blockId)
    +    val _bytes = blockManager.dataSerialize(blockId, values)
    +    putToTachyonStore(blockId, _bytes, returnValues)
    +  }
    +
    +  private def putToTachyonStore(
    +    blockId: BlockId,
    +    _bytes: ByteBuffer,
    +    returnValues: Boolean): PutResult = {
    +    // So that we do not modify the input offsets !
    +    // duplicate does not copy buffer, so inexpensive
    +    val bytes = _bytes.duplicate()
    +    bytes.rewind()
    +    logDebug("Attempting to put block " + blockId + " into Tachyon")
    +    val startTime = System.currentTimeMillis
    +    val file = tachyonManager.getFile(blockId)
    +    val os = file.getOutStream(WriteType.TRY_CACHE)
    +    os.write(bytes.array())
    --- End diff --
    
    Ah, I see that though it returns a FileOutputStream, the method return type is actually
just OutStream, which does not provide the ByteBuffer version. Peculiar, but I suppose this
is the best version for now, assuming our byte buffers are always array-able.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message