Slide 41
Slide 41 text
tachyon/worker/block/allocator/MaxFreeAllocator.java
@Override
public TempBlockMeta allocateBlock(long userId, long blockId, long blockSize
BlockStoreLocation location) throws IOException {
StorageDir candidateDir = null;
long maxFreeBytes = blockSize;
if (location.equals(BlockStoreLocation.anyTier())) {
for (StorageTier tier : mMetaManager.getTiers()) {
for (StorageDir dir : tier.getStorageDirs()) {
if (dir.getAvailableBytes() >= maxFreeBytes) {
maxFreeBytes = dir.getAvailableBytes();
candidateDir = dir;
}
}
}
} else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAli
StorageTier tier = mMetaManager.getTier(location.tierAlias());
for (StorageDir dir : tier.getStorageDirs()) {
if (dir.getAvailableBytes() >= maxFreeBytes) {
maxFreeBytes = dir.getAvailableBytes();
candidateDir = dir;
}
}
}
return candidateDir != null ?
new TempBlockMeta(userId, blockId, blockSize, candidateDir) : null;
}
tachyon/worker/block/allocator/MaxFreeAllocator.java
@Override
public TempBlockMeta allocateBlock(long userId, long blockId, long blockSize
BlockStoreLocation location) throws IOException {
StorageDir candidateDir = null;
if (location.equals(BlockStoreLocation.anyTier())) {
for (StorageTier tier : mMetaManager.getTiers()) {
candidateDir = getCandidateDirInTier(tier, blockSize);
if (candidateDir != null) {
return new TempBlockMeta(userId, blockId, blockSize, candidateDir);
}
}
} else if (location.equals(BlockStoreLocation.anyDirInTier(location.tierAli
StorageTier tier = mMetaManager.getTier(location.tierAlias());
candidateDir = getCandidateDirInTier(tier, blockSize);
}
return candidateDir != null ?
new TempBlockMeta(userId, blockId, blockSize, candidateDir) : null;
}
private StorageDir getCandidateDirInTier(StorageTier tier, long blockSize) {
StorageDir candidateDir = null;
long maxFreeBytes = blockSize - 1;
for (StorageDir dir : tier.getStorageDirs()) {
if (dir.getAvailableBytes() > maxFreeBytes) {
maxFreeBytes = dir.getAvailableBytes();
candidateDir = dir;
}
}
return candidateDir;
}
Call to the extracted method Moved to the extracted method
Parent block mapping