-
Notifications
You must be signed in to change notification settings - Fork 588
HDDS-12397. Persist putBlock for closed container. #7943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa72522
f3f8612
d6e68c6
5cca418
9ceb263
62375dd
c3797f0
0189a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,6 +98,80 @@ public long putBlock(Container container, BlockData data, | |
| data, endOfBlock); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public long putBlockForClosedContainer(Container container, BlockData data, boolean overwriteBcsId) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there are lots of warnings due to raw use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. We can do that in the main branch as an improvement.
aswinshakil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| throws IOException { | ||
| Preconditions.checkNotNull(data, "BlockData cannot be null for put operation."); | ||
| Preconditions.checkState(data.getContainerID() >= 0, "Container Id cannot be negative"); | ||
|
|
||
| KeyValueContainerData containerData = (KeyValueContainerData) container.getContainerData(); | ||
|
|
||
| // We are not locking the key manager since RocksDB serializes all actions | ||
| // against a single DB. We rely on DB level locking to avoid conflicts. | ||
| try (DBHandle db = BlockUtils.getDB(containerData, config)) { | ||
| // This is a post condition that acts as a hint to the user. | ||
| // Should never fail. | ||
| Preconditions.checkNotNull(db, DB_NULL_ERR_MSG); | ||
|
|
||
| long blockBcsID = data.getBlockCommitSequenceId(); | ||
| long containerBcsID = containerData.getBlockCommitSequenceId(); | ||
|
|
||
| // Check if the block is already present in the DB of the container to determine whether | ||
| // the blockCount is already incremented for this block in the DB or not. | ||
| long localID = data.getLocalID(); | ||
| boolean incrBlockCount = false; | ||
|
|
||
| // update the blockData as well as BlockCommitSequenceId here | ||
| try (BatchOperation batch = db.getStore().getBatchHandler() | ||
| .initBatchOperation()) { | ||
| // If block already exists in the DB, blockCount should not be incremented. | ||
| if (db.getStore().getBlockDataTable().get(containerData.getBlockKey(localID)) == null) { | ||
| incrBlockCount = true; | ||
| } | ||
|
|
||
| db.getStore().getBlockDataTable().putWithBatch(batch, containerData.getBlockKey(localID), data); | ||
| if (overwriteBcsId && blockBcsID > containerBcsID) { | ||
| db.getStore().getMetadataTable().putWithBatch(batch, containerData.getBcsIdKey(), blockBcsID); | ||
| } | ||
|
|
||
| // Set Bytes used, this bytes used will be updated for every write and | ||
| // only get committed for every put block. In this way, when datanode | ||
| // is up, for computation of disk space by container only committed | ||
| // block length is used, And also on restart the blocks committed to DB | ||
| // is only used to compute the bytes used. This is done to keep the | ||
| // current behavior and avoid DB write during write chunk operation. | ||
| db.getStore().getMetadataTable().putWithBatch(batch, containerData.getBytesUsedKey(), | ||
| containerData.getBytesUsed()); | ||
|
|
||
| // Set Block Count for a container. | ||
| if (incrBlockCount) { | ||
| db.getStore().getMetadataTable().putWithBatch(batch, containerData.getBlockCountKey(), | ||
| containerData.getBlockCount() + 1); | ||
| } | ||
|
|
||
| db.getStore().getBatchHandler().commitBatchOperation(batch); | ||
| } | ||
|
|
||
| if (overwriteBcsId && blockBcsID > containerBcsID) { | ||
| container.updateBlockCommitSequenceId(blockBcsID); | ||
| } | ||
|
|
||
| // Increment block count in-memory after the DB update. | ||
| if (incrBlockCount) { | ||
| containerData.incrBlockCount(); | ||
| } | ||
|
|
||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Block {} successfully persisted for closed container {} with bcsId {} chunk size {}", | ||
| data.getBlockID(), containerData.getContainerID(), blockBcsID, data.getChunks().size()); | ||
| } | ||
| return data.getSize(); | ||
| } | ||
| } | ||
|
|
||
| public long persistPutBlock(KeyValueContainer container, | ||
| BlockData data, boolean endOfBlock) | ||
| throws IOException { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a flag to overwrite the BCSID? Shouldn't it always be an automatic greater-than check?