Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
e41cab04
Commit
e41cab04
authored
12 years ago
by
root
Browse files
Options
Downloads
Patches
Plain Diff
Avoid creating an extra buffer when saving a stream of values as DISK_ONLY
parent
33fb373e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/src/main/scala/spark/storage/BlockStore.scala
+24
-20
24 additions, 20 deletions
core/src/main/scala/spark/storage/BlockStore.scala
with
24 additions
and
20 deletions
core/src/main/scala/spark/storage/BlockStore.scala
+
24
−
20
View file @
e41cab04
package
spark.storage
import
java.io.
{
File
,
RandomAccessFile
}
import
java.io.
{
File
,
FileOutputStream
,
RandomAccessFile
}
import
java.nio.ByteBuffer
import
java.nio.channels.FileChannel.MapMode
import
java.util.
{
LinkedHashMap
,
UUID
}
...
...
@@ -8,12 +8,14 @@ import java.util.concurrent.{ArrayBlockingQueue, ConcurrentHashMap}
import
scala.collection.mutable.ArrayBuffer
import
it.unimi.dsi.fastutil.io.FastBufferedOutputStream
import
spark.
{
Utils
,
Logging
,
Serializer
,
SizeEstimator
}
/**
* Abstract class to store blocks
*/
abstract
class
BlockStore
(
blockManager
:
BlockManager
)
extends
Logging
{
abstract
class
BlockStore
(
val
blockManager
:
BlockManager
)
extends
Logging
{
initLogging
()
def
putBytes
(
blockId
:
String
,
bytes
:
ByteBuffer
,
level
:
StorageLevel
)
...
...
@@ -217,25 +219,28 @@ class DiskStore(blockManager: BlockManager, rootDirs: String)
logDebug
(
"Attempting to put block "
+
blockId
)
val
startTime
=
System
.
currentTimeMillis
val
file
=
createFile
(
blockId
)
if
(
file
!=
null
)
{
val
channel
=
new
RandomAccessFile
(
file
,
"rw"
).
getChannel
()
val
buffer
=
channel
.
map
(
MapMode
.
READ_WRITE
,
0
,
bytes
.
limit
)
buffer
.
put
(
bytes
)
channel
.
close
()
val
finishTime
=
System
.
currentTimeMillis
logDebug
(
"Block %s stored to file of %d bytes to disk in %d ms"
.
format
(
blockId
,
bytes
.
limit
,
(
finishTime
-
startTime
)))
}
else
{
logError
(
"File not created for block "
+
blockId
)
}
val
channel
=
new
RandomAccessFile
(
file
,
"rw"
).
getChannel
()
val
buffer
=
channel
.
map
(
MapMode
.
READ_WRITE
,
0
,
bytes
.
limit
)
buffer
.
put
(
bytes
)
channel
.
close
()
val
finishTime
=
System
.
currentTimeMillis
logDebug
(
"Block %s stored to file of %d bytes to disk in %d ms"
.
format
(
blockId
,
bytes
.
limit
,
(
finishTime
-
startTime
)))
}
def
putValues
(
blockId
:
String
,
values
:
Iterator
[
Any
],
level
:
StorageLevel
)
:
Either
[
Iterator
[
Any
]
,
ByteBuffer
]
=
{
val
bytes
=
dataSerialize
(
values
)
logDebug
(
"Converted block "
+
blockId
+
" to "
+
bytes
.
limit
+
" bytes"
)
putBytes
(
blockId
,
bytes
,
level
)
return
Right
(
bytes
)
:
Either
[
Iterator
[
Any
]
,
ByteBuffer
]
=
{
logDebug
(
"Attempting to write values for block "
+
blockId
)
val
file
=
createFile
(
blockId
)
val
fileOut
=
new
FastBufferedOutputStream
(
new
FileOutputStream
(
file
))
val
objOut
=
blockManager
.
serializer
.
newInstance
().
serializeStream
(
fileOut
)
objOut
.
writeAll
(
values
)
objOut
.
close
()
// Return a byte buffer for the contents of the file
val
channel
=
new
RandomAccessFile
(
file
,
"rw"
).
getChannel
()
Right
(
channel
.
map
(
MapMode
.
READ_WRITE
,
0
,
channel
.
size
()))
}
def
getBytes
(
blockId
:
String
)
:
Option
[
ByteBuffer
]
=
{
...
...
@@ -267,8 +272,7 @@ class DiskStore(blockManager: BlockManager, rootDirs: String)
newFile
.
getParentFile
.
mkdirs
()
return
newFile
}
else
{
logError
(
"File for block "
+
blockId
+
" already exists on disk, "
+
file
)
return
null
throw
new
Exception
(
"File for block "
+
blockId
+
" already exists on disk, "
+
file
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment