-
Notifications
You must be signed in to change notification settings - Fork 902
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
Add API for Bookie checksum verification writeFlags #2182
base: master
Are you sure you want to change the base?
Conversation
@eolivelli @reddycharan Check this out. |
43635b3
to
01eb1ce
Compare
DEFERRED_SYNC(0x1 << 0); | ||
DEFERRED_SYNC(0x1 << 0), | ||
/** | ||
* Bits 1,2,3 - value 0. |
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.
-
For digesttype we need 3 bits, instead of taking Bits 1, 2, 3 I would suggest you to take Bits 2, 3, 4. This gives some space for SYNC types (REGULAR_SYNC and DEFERRED_SYNC). Currently it might need just 2 values (0/1) but it is better to be safe to leave space for expansion.
-
For reserving bits for digesttype, we should declare something like
static final int DIGEST_TYPE_BITS = 0x7 << 2;
as static int value. By doing so we are declaring that we need three bits and it would be bits 2, 3, 4.
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.
- That's a great point, will update it.
- I am not sure what the benefit will be. Since this would require code changes, someone may still mess it up. Currently, we don't throw exceptions in
getWriteFlags()
method, silently ignoring unexpected values, otherwise I could add up some tests that would have failed if someone tried to re-use them.
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.
yes, we have to use this static final int DIGEST_TYPE_BITS = 0x7 << 2;
in getWriteFlags()
method. Basically to know the digestType we should do logical and with DIGEST_TYPE_BITS first and then do the logical and with the corresponding enum value. Basically we are making it clear in getWriteFlags method that these bits are considered to be related to DigestType.
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.
Yeah, I did very lame mistake with bit manipulation here. 🤦♂️
With this logic, everything will become DigestType.DUMMY
. I will add a test to cover this.
731cf28
to
4eca065
Compare
return ONLY_DEFERRED_SYNC; | ||
writeFlags.add(DEFERRED_SYNC); | ||
} | ||
if ((flagValue & DIGEST_TYPE_DUMMY.value) == DIGEST_TYPE_DUMMY.value) { |
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.
Btw what if in this 'flagValue' int multiple digesttypes are enabled? How do we handle this error scenario?
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.
We cannot have multiple digestTypes being represented by a single int value. The server initializes the digestType based on the first ever flag value received and doesn't allow it to get updated (unless it was disabled earlier and then enabled).
We would essentially rely on client to ensure that it doesn't get corrupted. The writeFlags would be automatically set based on digestType. If the client re-opens a writeHandle again (for example, replication), then those bits would be automatically set based on metadata.
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 have to define more constants, one for each supported digest type?
The writer already knows the current digest type.
We can just have only one single enum value.
We are not constrained to map the API 1-1 to the wire protocol.
Side note: we cannot merge this change until the work on the bookie side is not ready and committed.
We can release a bookie with some unused features but once we commit to the public client API the feature must be available on the server side.
How would server know the digestType if we just have a single enum to represent them all. We would then need bit manipulation logic at other places to decode those bits to determine the type. This is helping consolidate some of it.
That is fine, I wanted to put this PR out to get some feedback and also reserve the bits from writeFlags. |
On the client API we should only have one WriteFlag CHECKSUM_VERIFICATION, as the LedgerHandle already knows the digest type. On the wire we can still send more detail to the bookie, still using the 'flags' field Another question: MAC needs a password, how will you handle it? We could say that MAC is not supported. |
I guess that comment is coming based on the fact that the WriteFlag enum is based in That being said, I wouldn't ask the app developer to add the corresponding flag on their own. Rather, it would get added automatically as part of LedgerHandle. Does that seem fine?
We are sending ledger key as part of the request too, hence we can use it. |
@eolivelli Any comments here? |
the MAC part is okay. Still I think we must have only one enum value on the WriteFlags enum. |
So if I understand this correctly, we should copy over a writeFlag class to server side, have only 2 flags at the client level. |
@eolivelli @sijie Thoughts? |
Sorry for late reply, I missed the notification. Yes, on the client API we need only two flags. For the server I like option 2, that is to create two methods: one for DEFERRED_SYNC and one for getting the DigestType |
@karanmehta93 |
@eolivelli Currently I am not working, busy with some internal stuff. |
@karanmehta93 @reddycharan @jvrao |
@eolivelli Apologies for late reply. I tried re-factoring the code but it's seems like a bigger effort. |
I hope you will be able to port back your change to Apache Repo, |
Are you fine with the approach I have in this PR? @eolivelli If yes, I can bring the other patches in too. |
@karanmehta93 We should see opinions for others. I don't want to see new diverging forks, especially about wire protocol |
fix old workflow,please see #3455 for detail |
Descriptions of the changes in this PR:
Motivation
Reserving the bits from
WriteFlag
so that clients can send the checksum information to the bookiesChanges
Updated
WriteFlag
classBit no 2-4 (from the right) indicates checksum type.
0 --> No verification enabled
1 --> DIGEST_TYPE_CRC32
2 --> DIGEST_TYPE_MAC
3 -->DIGEST_TYPE_CRC32C
Bit no 0 (from the right) is currently being used for
DEFERRED_SYNC
option.Master Issue: #2174