navinko commented on code in PR #10211:
URL: https://github.com/apache/ozone/pull/10211#discussion_r3219533715
##########
hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/ha/SequenceIdGenerator.java:
##########
@@ -128,18 +128,18 @@ public long getNextId(String sequenceIdName) throws
SCMException {
Preconditions.checkArgument(Long.MAX_VALUE - batch.lastId >=
batchSize);
long nextLastId = batch.lastId +
- ((sequenceIdName.equals(CERTIFICATE_ID)) ? 1 : batchSize);
+ (idType == SequenceIdType.CERTIFICATE_ID ? 1 : batchSize);
- if (stateManager.allocateBatch(sequenceIdName,
+ if (stateManager.allocateBatch(idType.getDbKey(),
prevLastId, nextLastId)) {
batch.lastId = nextLastId;
LOG.info("Allocate a batch for {}, change lastId from {} to {}.",
- sequenceIdName, prevLastId, batch.lastId);
+ idType, prevLastId, batch.lastId);
break;
}
// reload lastId from RocksDB.
- batch.lastId = stateManager.getLastId(sequenceIdName);
+ batch.lastId = stateManager.getLastId(idType.getDbKey());
Review Comment:
Thanks @sreejasahithi @szetszwo for the suggestion!
I have removed the unused method fromDbKey and DB_KEY_MAP and made all
constant under SequenceIdGenerator private alongwith EnumMap as unmodifiable
and dis suggested changes in test classes.
I've updated code for StateManagerImpl too , the parameters and map keys to
use SequenceIdType instead of Strings. Further , to handle how these new Enums
are serialized across the Ratis and safely deserialized from existing RocksDB
bytes, I implemented the ScmSequenceIdTypeCodec and registered with
ScmCodecFactory. This ensures the Enums translate perfectly into our legacy
byte format .
Also referred existing TestPipelineIDCodec to create new unit test for codec
and verifies the serialization and deserialzation. In the
LegacyStringSequenceIdCodecForTesting class simulated, how Sequence IDs were
serialized before the Enum refactoring.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]