Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Guo committed Aug 18, 2023
1 parent a6b696c commit be3d55b
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class MySqlNamedBlobDb implements NamedBlobDb {
* Set named blob state to be READY and delete timestamp to null for TtlUpdate case
*/
private static final String TTL_UPDATE_QUERY =
String.format("UPDATE %s SET %s, %s = NULL WHERE %s", NAMED_BLOBS_V2, STATE_MATCH, DELETED_TS, PK_MATCH_VERSION);
String.format("UPDATE %s SET %s = ?, %s = NULL WHERE %s", NAMED_BLOBS_V2, BLOB_STATE, DELETED_TS, PK_MATCH_VERSION);

/**
* Pull the stale blobs that need to be cleaned up
Expand Down Expand Up @@ -365,7 +365,7 @@ public CompletableFuture<PutResult> updateBlobStateToReady(NamedBlobRecord recor
(accountId, containerId, connection) -> {
long startTime = this.time.milliseconds();
logger.trace("Updating to READY for Named Blob: {}", record);
PutResult result = apply_ttl_update(record, accountId, containerId, connection);
PutResult result = apply_ttl_update(record, NamedBlobState.READY, accountId, containerId, connection);
metricsRecoder.namedTtlupdateTimeInMs.update(this.time.milliseconds() - startTime);
return result;
}, null);
Expand Down Expand Up @@ -657,14 +657,15 @@ private PutResult run_put_v2(NamedBlobRecord record, NamedBlobState state, short
return new PutResult(record);
}

private PutResult apply_ttl_update(NamedBlobRecord record, short accountId, short containerId, Connection connection)
throws Exception{
private PutResult apply_ttl_update(NamedBlobRecord record, NamedBlobState namedBlobState, short accountId,
short containerId, Connection connection) throws Exception {
String query = "";
try (PreparedStatement statement = connection.prepareStatement(TTL_UPDATE_QUERY)) {
statement.setInt(1, accountId);
statement.setInt(2, containerId);
statement.setString(3, record.getBlobName());
statement.setLong(4, record.getVersion());
statement.setInt(1, namedBlobState.ordinal());
statement.setInt(2, accountId);
statement.setInt(3, containerId);
statement.setString(4, record.getBlobName());
statement.setLong(5, record.getVersion());
query = statement.toString();
logger.debug("Updating TTL in MySql. Query {}", query);
int rowCount = statement.executeUpdate();
Expand Down Expand Up @@ -771,7 +772,8 @@ public CompletableFuture<PutResult> ttlUpdate(NamedBlobRecord record, NamedBlobS
long startTime = this.time.milliseconds();
logger.trace("NamedBlobPutInfo: accountId='{}', containerId='{}', blobName='{}'", accountId, containerId,
record.getBlobName());
//for ttl update, get the blob id first before insert a new record.
//for ttl update, we are only able to get accountName, containerName and blobName.
//so before update, we need to get the blob version and blob id first to construct the output putResult.
NamedBlobRecord recordCurrent;
try {
recordCurrent =
Expand All @@ -782,7 +784,8 @@ public CompletableFuture<PutResult> ttlUpdate(NamedBlobRecord record, NamedBlobS
record.getAccountName(), record.getContainerName(), record.getBlobName());
}
record.setBlobId(recordCurrent.getBlobId());
PutResult putResult = run_put_v2(record, state, accountId, containerId, connection);
record.setVersion(recordCurrent.getVersion());
PutResult putResult = apply_ttl_update(record, state, accountId, containerId, connection);
metricsRecoder.namedBlobPutTimeInMs.update(this.time.milliseconds() - startTime);
return putResult;
}, null);
Expand Down

0 comments on commit be3d55b

Please sign in to comment.