Skip to content
Closed
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 @@ -159,7 +159,7 @@ public void testKafkaOffsetHolderEquality() {
null));
tester.testEquals();
}
};
}

class CounterSourceConnector extends SourceConnector {
public static class CounterSourceConnectorConfig extends AbstractConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,14 +528,22 @@ public Void updateToFinished(String partitionToken) {
}

/**
* Update the partition watermark to the given timestamp.
* Update the partition watermark to the given timestamp if the given timestamp is larger than
* the existing value.
*
* @param partitionToken the partition unique identifier
* @param watermark the new partition watermark
* @return the commit timestamp of the read / write transaction
*/
public Void updateWatermark(String partitionToken, Timestamp watermark) {
transaction.buffer(createUpdateMetadataWatermarkMutationFrom(partitionToken, watermark));
Timestamp currentWatermark = getWatermarkForPartition(partitionToken);
if (currentWatermark == null) {
LOG.debug("Partiton {} cannot be found.", partitionToken);
return null;
}
if (watermark.compareTo(currentWatermark) > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this compare to run (since it's not part of the transaction)? Does it happen atomically along with the read and write? Or are we getting a snapshot, comparing it on the user worker and then writing the value? I'm asking because we need to make sure that if two different processes are trying to update the watermark for the same partition they won't race with each other.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This compare happens transaction. The function updatewermark is in transaction:
public void updateWatermark(String partitionToken, Timestamp watermark) {
runInTransaction(
transaction -> transaction.updateWatermark(partitionToken, watermark), "updateWatermark");
}

transaction.buffer(createUpdateMetadataWatermarkMutationFrom(partitionToken, watermark));
}
return null;
}

Expand Down Expand Up @@ -582,6 +590,52 @@ public Void updateWatermark(String partitionToken, Timestamp watermark) {
}
}

/**
* Fetches the watermark for a given partition token.
*
* @param partitionToken the partition unique identifier
* @return the watermark for the given token if it exists. Otherwise, it returns null.
*/
public @Nullable Timestamp getWatermarkForPartition(String partitionToken) {
Struct row =
* transaction.readRow(metadataTableName, Key.of(singerId), Collections.singleton(column));
final Statement statement;
if (this.dialect == Dialect.POSTGRESQL) {
statement =
Statement.newBuilder(
"SELECT \""
+ COLUMN_WATERMARK
+ "\" FROM \""
+ metadataTableName
+ "\" WHERE \""
+ COLUMN_PARTITION_TOKEN
+ "\" = $1")
.bind("p1")
.to(partitionToken)
.build();
} else {
statement =
Statement.newBuilder(
"SELECT "
+ COLUMN_WATERMARK
+ " FROM "
+ metadataTableName
+ " WHERE "
+ COLUMN_PARTITION_TOKEN
+ " = @partition")
.bind("partition")
.to(partitionToken)
.build();
}
try (ResultSet resultSet =
transaction.executeQuery(statement, Options.tag("query=getWatermarkForPartition"))) {
if (resultSet.next()) {
return resultSet.getTimestamp(COLUMN_WATERMARK);
}
return null;
}
}

private Mutation createInsertMetadataMutationFrom(PartitionMetadata partitionMetadata) {
return Mutation.newInsertBuilder(metadataTableName)
.set(COLUMN_PARTITION_TOKEN)
Expand Down
2 changes: 2 additions & 0 deletions test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "usr/local/google/home/xuechen/Documents/beam-master/test.h"
Test
Loading