Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,17 @@ private[spark] class BlockManagerInfo(

updateLastSeenMs()

var blockExists = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although you could just assign val blockExists = _blocks.containsKey(blockId) once and reuse it instead of a var, it's minor. This looks good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea, i have modified it, thank you

var originalMemSize: Long = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pull out a var here?

var originalDiskSize: Long = 0

if (_blocks.containsKey(blockId)) {
// The block exists on the slave already.
val blockStatus: BlockStatus = _blocks.get(blockId)
val originalLevel: StorageLevel = blockStatus.storageLevel
val originalMemSize: Long = blockStatus.memSize
originalMemSize = blockStatus.memSize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLocks of code even farther down can reuse these new values and need similar changes to the log comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok,thanks for suggestion, I have modified it

originalDiskSize = blockStatus.diskSize
blockExists = true

if (originalLevel.useMemory) {
_remainingMem += originalMemSize
Expand All @@ -516,19 +522,32 @@ private[spark] class BlockManagerInfo(
* They can be both larger than 0, when a block is dropped from memory to disk.
* Therefore, a safe way to set BlockStatus is to set its info in accurate modes. */
var blockStatus: BlockStatus = null

if (storageLevel.useMemory) {
blockStatus = BlockStatus(storageLevel, memSize = memSize, diskSize = 0)
_blocks.put(blockId, blockStatus)
_remainingMem -= memSize
logInfo("Added %s in memory on %s (size: %s, free: %s)".format(
blockId, blockManagerId.hostPort, Utils.bytesToString(memSize),
Utils.bytesToString(_remainingMem)))
if (blockExists) {
logInfo("Updated %s in memory on %s (current size: %s, original size %s, free: %s)".format(
blockId, blockManagerId.hostPort, Utils.bytesToString(memSize),
Utils.bytesToString(originalMemSize),Utils.bytesToString(_remainingMem)))
} else {
logInfo("Added %s in memory on %s (size: %s, free: %s)".format(
blockId, blockManagerId.hostPort, Utils.bytesToString(memSize),
Utils.bytesToString(_remainingMem)))
}
}
if (storageLevel.useDisk) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the disk case need a similar treatment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have modified the disk case, and add a "update" style log info, any other suggestions? thank you

blockStatus = BlockStatus(storageLevel, memSize = 0, diskSize = diskSize)
_blocks.put(blockId, blockStatus)
logInfo("Added %s on disk on %s (size: %s)".format(
blockId, blockManagerId.hostPort, Utils.bytesToString(diskSize)))
if (blockExists) {
logInfo("Updated %s on disk on %s (current size: %s, original size %s)".format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still not using string interpolation, please do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry,i don't understand the meaning of "string interpolation" very clearly, is it like this: logInfo(s"Added $blockId on disk on ${blockManagerId.hostPort} (size: $diskSize)") ? but this is different from other log infos in this file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you've got it. It's worth changing all of the related log messages here, but not necessarily every one in the file. We are slowly updating to use string interpolation as this code gets updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok,i have modified it, thank you!

blockId, blockManagerId.hostPort, Utils.bytesToString(diskSize),
Utils.bytesToString(originalDiskSize)))
} else {
logInfo("Added %s on disk on %s (size: %s)".format(
blockId, blockManagerId.hostPort, Utils.bytesToString(diskSize)))
}
}
if (!blockId.isBroadcast && blockStatus.isCached) {
_cachedBlocks += blockId
Expand Down