@@ -55,6 +55,8 @@ enum Flags {
5555
5656 final static byte FLAGS_DEFAULT_VALUE = (byte ) 0 ;
5757 final static long UNKNOWN_ORIGINAL_MESSAGE_OFFSET = -1 ;
58+ // The life version when the operation is trigger by the requests from frontend.
59+ final static short LIFE_VERSION_FROM_FRONTEND = -1 ;
5860
5961 private final static int BLOB_SIZE_IN_BYTES = 8 ;
6062 private final static int OFFSET_SIZE_IN_BYTES = 8 ;
@@ -186,6 +188,15 @@ enum Flags {
186188 this (size , offset , flags , expiresAtMs , offset .getOffset (), operationTimeInMs , accountId , containerId , lifeVersion );
187189 }
188190
191+ /**
192+ * Constructor to copy all data from a given {@link IndexValue}.
193+ * @param other the given {@link IndexValue}.
194+ */
195+ IndexValue (IndexValue other ) {
196+ this (other .getSize (), other .getOffset (), other .getFlags (), other .getExpiresAtMs (), other .getOriginalMessageOffset (),
197+ other .getOperationTimeInMs (), other .getAccountId (), other .getContainerId (), other .getLifeVersion ());
198+ }
199+
189200 /**
190201 * Constructs IndexValue based on the args passed
191202 * @param size the size of the blob that this index value refers to
@@ -243,6 +254,38 @@ boolean isFlagSet(Flags flag) {
243254 return ((getFlags () & (1 << flag .ordinal ())) != 0 );
244255 }
245256
257+ /**
258+ * Helper function for isFlagSet(Flags.Ttl_Update_Index).
259+ * @return true when the Ttl_Update_Index is set.
260+ */
261+ boolean isTTLUpdate () {
262+ return isFlagSet (Flags .Ttl_Update_Index );
263+ }
264+
265+ /**
266+ * Helper function for isFlagSet(Flags.Delete_Index).
267+ * @return true when the Delete_Index is set.
268+ */
269+ boolean isDelete () {
270+ return isFlagSet (Flags .Delete_Index );
271+ }
272+
273+ /**
274+ * Helper function for isFlagSet(Flags.Undelete_Index).
275+ * @return true when the Undelete_Index is set.
276+ */
277+ boolean isUndelete () {
278+ return isFlagSet (Flags .Undelete_Index );
279+ }
280+
281+ /**
282+ * Helper function to decide if this value is a put value or not.
283+ * @return true when it's not a put record.
284+ */
285+ boolean isPut () {
286+ return flags == FLAGS_DEFAULT_VALUE ;
287+ }
288+
246289 /**
247290 * @return the expiration time of the index value in ms
248291 */
@@ -279,6 +322,15 @@ short getContainerId() {
279322 return containerId ;
280323 }
281324
325+ /**
326+ * True when the life version is not from frontend requests.
327+ * @param lifeVersion the given life version.
328+ * @return true when it's not from frontend requests.
329+ */
330+ static boolean hasLifeVersion (short lifeVersion ) {
331+ return lifeVersion > LIFE_VERSION_FROM_FRONTEND ;
332+ }
333+
282334 /**
283335 * @return the lifeVersion of the {@link IndexValue}
284336 */
@@ -385,12 +437,11 @@ ByteBuffer getBytes() {
385437
386438 @ Override
387439 public String toString () {
388- return "Offset: " + offset + ", Size: " + getSize () + ", Deleted: " + isFlagSet (Flags .Delete_Index )
389- + ", TTL Updated: " + isFlagSet (Flags .Ttl_Update_Index ) + ", Undelete: " + isFlagSet (
390- Flags .Undelete_Index ) + ", ExpiresAtMs: " + getExpiresAtMs () + ", Original Message Offset: "
440+ return "Offset: " + offset + ", Size: " + getSize () + ", Deleted: " + isDelete () + ", TTL Updated: " + isTTLUpdate ()
441+ + ", Undelete: " + isUndelete () + ", ExpiresAtMs: " + getExpiresAtMs () + ", Original Message Offset: "
391442 + getOriginalMessageOffset () + (formatVersion != PersistentIndex .VERSION_0 ? (", OperationTimeAtSecs "
392- + getOperationTimeInMs () + ", AccountId " + getAccountId () + ", ContainerId " + getContainerId ())
393- : "" ) + ( formatVersion > PersistentIndex .VERSION_2 ? ", Life Version:" + lifeVersion : "" );
443+ + getOperationTimeInMs () + ", AccountId " + getAccountId () + ", ContainerId " + getContainerId ()) : "" ) + (
444+ formatVersion > PersistentIndex .VERSION_2 ? ", Life Version:" + lifeVersion : "" );
394445 }
395446
396447 /**
0 commit comments