Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public final class OmKeyInfo extends WithParentObjectId
implements CopyObject<OmKeyInfo>, WithTags {
private static final Logger LOG = LoggerFactory.getLogger(OmKeyInfo.class);

private static final Codec<OmKeyInfo> CODEC_TRUE = newCodec(true);
private static final Codec<OmKeyInfo> CODEC_FALSE = newCodec(false);
// Codecs for openKeyTable
private static final Codec<OmKeyInfo> CODEC_TRUE = newCodec(true, true);
private static final Codec<OmKeyInfo> CODEC_FALSE = newCodec(false, true);

// Codecs for keyTable
private static final Codec<OmKeyInfo> CODEC_KEY_TABLE_TRUE = newCodec(true, false);
private static final Codec<OmKeyInfo> CODEC_KEY_TABLE_FALSE = newCodec(false, false);
/**
* Metadata key flag to indicate whether a deleted key was a committed key.
* The flag is set when a committed key is deleted from AOS but still held in
Expand Down Expand Up @@ -131,19 +136,46 @@ private OmKeyInfo(Builder b) {
this.expectedDataGeneration = b.expectedDataGeneration;
}

private static Codec<OmKeyInfo> newCodec(boolean ignorePipeline) {
/**
* Creates a new codec for OmKeyInfo.
*
* @param ignorePipeline whether to ignore pipeline info during serialization
* @param isOpenKey true for openKeyTable (includes expectedDataGeneration/expectedETag),
* false for keyTable (excludes these fields)
* @return the codec
*/
private static Codec<OmKeyInfo> newCodec(boolean ignorePipeline, boolean isOpenKey) {
return new DelegatedCodec<>(
Proto2Codec.get(KeyInfo.getDefaultInstance()),
OmKeyInfo::getFromProtobuf,
k -> k.getProtobuf(ignorePipeline, ClientVersion.CURRENT_VERSION),
k -> k.getProtobuf(ignorePipeline, ClientVersion.CURRENT_VERSION, isOpenKey),
OmKeyInfo.class);
}

public static Codec<OmKeyInfo> getCodec(boolean ignorePipeline) {
LOG.debug("OmKeyInfo.getCodec ignorePipeline = {}", ignorePipeline);
/**
* Gets the codec for openKeyTable. This codec includes expectedDataGeneration
* and expectedETag fields during serialization.
*
* @param ignorePipeline whether to ignore pipeline info
* @return the codec for openKeyTable
*/
public static Codec<OmKeyInfo> getOpenKeyTableCodec(boolean ignorePipeline) {
LOG.debug("OmKeyInfo.getOpenKeyTableCodec ignorePipeline = {}", ignorePipeline);
return ignorePipeline ? CODEC_TRUE : CODEC_FALSE;
}

/**
* Gets the codec for keyTable. This codec excludes fields are only
* meaningful for open keys.
*
* @param ignorePipeline whether to ignore pipeline info
* @return the codec for keyTable
*/
public static Codec<OmKeyInfo> getKeyTableCodec(boolean ignorePipeline) {
LOG.debug("OmKeyInfo.getKeyTableCodec ignorePipeline = {}", ignorePipeline);
return ignorePipeline ? CODEC_KEY_TABLE_TRUE : CODEC_KEY_TABLE_FALSE;
}

public String getVolumeName() {
return volumeName;
}
Expand Down Expand Up @@ -738,7 +770,20 @@ public KeyInfo getNetworkProtobuf(String fullKeyName, int clientVersion,
* @return KeyInfo
*/
public KeyInfo getProtobuf(boolean ignorePipeline, int clientVersion) {
return getProtobuf(ignorePipeline, null, clientVersion, false);
return getProtobuf(ignorePipeline, null, clientVersion, false, true);
}

/**
* Gets KeyInfo for persistence with control over fields only used in openKeyTable.
*
* @param ignorePipeline true for persist to DB, false for network transmit.
* @param clientVersion the client version
* @param isOpenKey true for openKeyTable, false for keyTable
* @return KeyInfo
*/
public KeyInfo getProtobuf(boolean ignorePipeline, int clientVersion,
boolean isOpenKey) {
return getProtobuf(ignorePipeline, null, clientVersion, false, isOpenKey);
}

/**
Expand All @@ -750,6 +795,22 @@ public KeyInfo getProtobuf(boolean ignorePipeline, int clientVersion) {
*/
private KeyInfo getProtobuf(boolean ignorePipeline, String fullKeyName,
int clientVersion, boolean latestVersionBlocks) {
return getProtobuf(ignorePipeline, fullKeyName, clientVersion, latestVersionBlocks, true);
}

/**
* Gets KeyInfo with all parameters.
*
* @param ignorePipeline ignore pipeline flag
* @param fullKeyName user given key name
* @param clientVersion the client version
* @param latestVersionBlocks whether to include only latest version blocks
* @param isOpenKey true for openKeyTable, false for keyTable
* @return key info object
*/
private KeyInfo getProtobuf(boolean ignorePipeline, String fullKeyName,
int clientVersion, boolean latestVersionBlocks,
boolean isOpenKey) {
long latestVersion = keyLocationVersions.isEmpty() ? -1 :
keyLocationVersions.get(keyLocationVersions.size() - 1).getVersion();

Expand Down Expand Up @@ -801,8 +862,11 @@ private KeyInfo getProtobuf(boolean ignorePipeline, String fullKeyName,
kb.setFileEncryptionInfo(OMPBHelper.convert(encInfo));
}
kb.setIsFile(isFile);
if (expectedDataGeneration != null) {
kb.setExpectedDataGeneration(expectedDataGeneration);

if (isOpenKey) {
if (expectedDataGeneration != null) {
kb.setExpectedDataGeneration(expectedDataGeneration);
}
}
if (ownerName != null) {
kb.setOwnerName(ownerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
* admin wants to confirm if a given key is deleted from deletedTable metadata.
*/
public class RepeatedOmKeyInfo implements CopyObject<RepeatedOmKeyInfo> {
private static final Codec<RepeatedOmKeyInfo> CODEC_TRUE = newCodec(true);
private static final Codec<RepeatedOmKeyInfo> CODEC_FALSE = newCodec(false);

private static final Codec<RepeatedOmKeyInfo> CODEC_TRUE = newCodec(true, true);
private static final Codec<RepeatedOmKeyInfo> CODEC_FALSE = newCodec(false, true);

// Codecs for deletedTable - exclude fields only used in openKeyTable
private static final Codec<RepeatedOmKeyInfo> CODEC_DELETED_TABLE_TRUE = newCodec(true, false);
private static final Codec<RepeatedOmKeyInfo> CODEC_DELETED_TABLE_FALSE = newCodec(false, false);

private final List<OmKeyInfo> omKeyInfoList;
/**
Expand All @@ -51,18 +56,36 @@ public class RepeatedOmKeyInfo implements CopyObject<RepeatedOmKeyInfo> {
*/
private final long bucketId;

private static Codec<RepeatedOmKeyInfo> newCodec(boolean ignorePipeline) {
private static Codec<RepeatedOmKeyInfo> newCodec(boolean ignorePipeline, boolean isOpenKey) {
return new DelegatedCodec<>(
Proto2Codec.get(RepeatedKeyInfo.getDefaultInstance()),
RepeatedOmKeyInfo::getFromProto,
k -> k.getProto(ignorePipeline, ClientVersion.CURRENT_VERSION),
k -> k.getProto(ignorePipeline, ClientVersion.CURRENT_VERSION, isOpenKey),
RepeatedOmKeyInfo.class);
}

public static Codec<RepeatedOmKeyInfo> getCodec(boolean ignorePipeline) {
/**
* Gets the codec for openKeyTable. This codec includes fields only used in
* openKeyTable during serialization.
*
* @param ignorePipeline whether to ignore pipeline info
* @return the codec for openKeyTable
*/
public static Codec<RepeatedOmKeyInfo> getOpenKeyTableCodec(boolean ignorePipeline) {
return ignorePipeline ? CODEC_TRUE : CODEC_FALSE;
}

/**
* Gets the codec for deletedTable. This codec excludes fields only used in
* openKeyTable during serialization, as deleted keys are committed keys.
*
* @param ignorePipeline whether to ignore pipeline info
* @return the codec for deletedTable
*/
public static Codec<RepeatedOmKeyInfo> getDeletedTableCodec(boolean ignorePipeline) {
return ignorePipeline ? CODEC_DELETED_TABLE_TRUE : CODEC_DELETED_TABLE_FALSE;
}

public RepeatedOmKeyInfo(long bucketId) {
this.omKeyInfoList = new ArrayList<>();
this.bucketId = bucketId;
Expand Down Expand Up @@ -129,9 +152,18 @@ public static RepeatedOmKeyInfo getFromProto(RepeatedKeyInfo repeatedKeyInfo) {
* @param compact true for persistence, false for network transmit
*/
public RepeatedKeyInfo getProto(boolean compact, int clientVersion) {
return getProto(compact, clientVersion, true);
}

/**
* @param compact true for persistence, false for network transmit
* @param clientVersion the client version
* @param isOpenKey true for openKeyTable, false for keyTable/deletedTable
*/
public RepeatedKeyInfo getProto(boolean compact, int clientVersion, boolean isOpenKey) {
List<KeyInfo> list = new ArrayList<>();
for (OmKeyInfo k : cloneOmKeyInfoList()) {
list.add(k.getProtobuf(compact, clientVersion));
list.add(k.getProtobuf(compact, clientVersion, isOpenKey));
}

RepeatedKeyInfo.Builder builder = RepeatedKeyInfo.newBuilder()
Expand Down
Loading
Loading