-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use operation attributes for implicit pre-read and insert mode of Put
- Loading branch information
Showing
12 changed files
with
367 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ain/java/com/scalar/db/transaction/consensuscommit/ConsensusCommitOperationAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.scalar.db.transaction.consensuscommit; | ||
|
||
import com.scalar.db.api.Put; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** A class to manage the operations attributes for Consensus Commit. */ | ||
public final class ConsensusCommitOperationAttribute { | ||
|
||
private static final String OPERATION_ATTRIBUTE_PREFIX = "cc-"; | ||
public static final String IMPLICIT_PRE_READ_ENABLED = | ||
OPERATION_ATTRIBUTE_PREFIX + "implicit-pre-read-enabled"; | ||
public static final String INSERT_MODE_ENABLED = | ||
OPERATION_ATTRIBUTE_PREFIX + "insert-mode-enabled"; | ||
|
||
private ConsensusCommitOperationAttribute() {} | ||
|
||
public static Put enableImplicitPreRead(Put put) { | ||
return Put.newBuilder(put).attribute(IMPLICIT_PRE_READ_ENABLED, "true").build(); | ||
} | ||
|
||
public static void enableImplicitPreRead(Map<String, String> attributes) { | ||
attributes.put(IMPLICIT_PRE_READ_ENABLED, "true"); | ||
} | ||
|
||
public static Put disableImplicitPreRead(Put put) { | ||
return Put.newBuilder(put).clearAttribute(IMPLICIT_PRE_READ_ENABLED).build(); | ||
} | ||
|
||
public static void disableImplicitPreRead(Map<String, String> attributes) { | ||
attributes.remove(IMPLICIT_PRE_READ_ENABLED); | ||
} | ||
|
||
public static Put enableInsertMode(Put put) { | ||
return Put.newBuilder(put).attribute(INSERT_MODE_ENABLED, "true").build(); | ||
} | ||
|
||
public static void enableInsertMode(Map<String, String> attributes) { | ||
attributes.put(INSERT_MODE_ENABLED, "true"); | ||
} | ||
|
||
public static Put disableInsertMode(Put put) { | ||
return Put.newBuilder(put).clearAttribute(INSERT_MODE_ENABLED).build(); | ||
} | ||
|
||
public static void disableInsertMode(Map<String, String> attributes) { | ||
attributes.remove(INSERT_MODE_ENABLED); | ||
} | ||
|
||
public static boolean isImplicitPreReadEnabled(Put put) { | ||
Optional<String> attribute = put.getAttribute(IMPLICIT_PRE_READ_ENABLED); | ||
return attribute.isPresent() && "true".equalsIgnoreCase(attribute.get()); | ||
} | ||
|
||
public static boolean isInsertModeEnabled(Put put) { | ||
Optional<String> attribute = put.getAttribute(INSERT_MODE_ENABLED); | ||
return attribute.isPresent() && "true".equalsIgnoreCase(attribute.get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.