Skip to content

add version in datalake table name #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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 @@ -30,6 +30,7 @@ public class DynamoDBSourceConnector extends SourceConnector {
private TablesProvider tablesProvider;

private List<String> consumableTables;
private String tableVersion;

private volatile Timer timer;

Expand Down Expand Up @@ -76,7 +77,7 @@ public void start(Map<String, String> properties) {
config.getSrcDynamoDBEnvTagValue());
}
}

tableVersion = config.getTableVersion();
startBackgroundReconfigurationTasks(this.context, config.getRediscoveryPeriod());
}

Expand Down Expand Up @@ -135,7 +136,9 @@ public List<Map<String, String>> taskConfigs(int maxTasks) {
Map<String, String> taskProps = new HashMap<>(configProperties);

taskProps.put(DynamoDBSourceTaskConfig.TABLE_NAME_CONFIG, table);

if (tableVersion != null && !tableVersion.isEmpty()) {
taskProps.put(DynamoDBSourceTaskConfig.TABLE_VERSION_CONFIG, tableVersion);
}
// In feature we might allow having more then one task per table for performance reasons.
// TaskID will be needed for KCL worker identifiers and also to orchestrate init sync.
taskProps.put(DynamoDBSourceTaskConfig.TASK_ID_CONFIG, "task-1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class DynamoDBSourceConnectorConfig extends AbstractConfig {
public static final String SRC_DYNAMODB_TABLE_WHITELIST_DISPLAY = "Tables whitelist";
public static final String SRC_DYNAMODB_TABLE_WHITELIST_DEFAULT = null;

public static final String SRC_DYNAMODB_TABLE_VERSION_CONFIG = "dynamodb.table.version";
public static final String SRC_DYNAMODB_TABLE_VERSION_DOC = "Define version of the table. This is used to create a unique table connector name for the table.";
public static final String SRC_DYNAMODB_TABLE_VERSION_DISPLAY = "Table version";
public static final String SRC_DYNAMODB_TABLE_VERSION_DEFAULT = "";

public static final String SRC_KCL_TABLE_BILLING_MODE_CONFIG = "kcl.table.billing.mode";
public static final String SRC_KCL_TABLE_BILLING_MODE_DOC = "Define billing mode for internal table created by the KCL library. Default is provisioned.";
public static final String SRC_KCL_TABLE_BILLING_MODE_DISPLAY = "KCL table billing mode";
Expand Down Expand Up @@ -176,6 +181,7 @@ public static ConfigDef baseConfigDef() {
ConfigDef.Width.MEDIUM,
SRC_DYNAMODB_TABLE_WHITELIST_DISPLAY)


.define(SRC_KCL_TABLE_BILLING_MODE_CONFIG,
ConfigDef.Type.STRING,
SRC_KCL_TABLE_BILLING_MODE_DEFAULT,
Expand All @@ -185,6 +191,15 @@ public static ConfigDef baseConfigDef() {
ConfigDef.Width.MEDIUM,
SRC_KCL_TABLE_BILLING_MODE_DISPLAY)

.define(SRC_DYNAMODB_TABLE_VERSION_CONFIG,
ConfigDef.Type.STRING,
SRC_DYNAMODB_TABLE_VERSION_DEFAULT,
ConfigDef.Importance.LOW,
SRC_DYNAMODB_TABLE_VERSION_DOC,
AWS_GROUP, 10,
ConfigDef.Width.MEDIUM,
SRC_DYNAMODB_TABLE_VERSION_DISPLAY)

.define(DST_TOPIC_PREFIX_CONFIG,
ConfigDef.Type.STRING,
DST_TOPIC_PREFIX_DEFAULT,
Expand Down Expand Up @@ -286,6 +301,10 @@ public List<String> getWhitelistTables() {
return getList(SRC_DYNAMODB_TABLE_WHITELIST_CONFIG) != null ? getList(SRC_DYNAMODB_TABLE_WHITELIST_CONFIG) : null;
}

public String getTableVersion() {
return getString(SRC_DYNAMODB_TABLE_VERSION_CONFIG);
}

public BillingMode getKCLTableBillingMode() {
return BillingMode.fromValue(getString(SRC_KCL_TABLE_BILLING_MODE_CONFIG));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void start(Map<String, String> configProperties) {
eventsQueue,
shardRegister);
}
kclWorker.start(client, dynamoDBStreamsClient, tableDesc.getTableName(), config.getTaskID(), config.getDynamoDBServiceEndpoint(), config.getKCLTableBillingMode());
kclWorker.start(client, dynamoDBStreamsClient, tableDesc.getTableName(), config.getTaskID(), config.getDynamoDBServiceEndpoint(), config.getTableVersion(), config.getKCLTableBillingMode());

shutdown = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ public class DynamoDBSourceTaskConfig extends DynamoDBSourceConnectorConfig {
public static final String TABLE_NAME_CONFIG = "table";
private static final String TABLE_NAME_DOC = "table for this task to watch for changes.";

public static final String TABLE_VERSION_CONFIG = "table.version";
private static final String TABLE_VERSION_DOC = "table version for this task to watch for changes.";

public static final String TASK_ID_CONFIG = "task.id";
private static final String TASK_ID_DOC = "Per table id of the task.";

private static final ConfigDef config = baseConfigDef()
.define(TABLE_NAME_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, TABLE_NAME_DOC)
.define(TASK_ID_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, TASK_ID_DOC);
.define(TASK_ID_CONFIG, ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, TASK_ID_DOC)
.define(TABLE_VERSION_CONFIG, ConfigDef.Type.STRING, "", ConfigDef.Importance.LOW, TABLE_VERSION_DOC);

public DynamoDBSourceTaskConfig(Map<String, String> props) {
super(config, props);
Expand All @@ -23,6 +27,10 @@ public String getTableName() {
return getString(TABLE_NAME_CONFIG);
}

public String getTableVersion() {
return getString(TABLE_VERSION_CONFIG);
}

public String getTaskID() {
return getString(TASK_ID_CONFIG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ public static Map<String, Object> toOffset(SourceInfo sourceInfo) {
offset.put(INIT_SYNC_START, sourceInfo.lastInitSyncStart.toEpochMilli());

if (sourceInfo.exclusiveStartKey != null) {
if (sourceInfo.exclusiveStartKey != null) {
try {
offset.put(EXCLUSIVE_START_KEY, objectMapper.writeValueAsString(sourceInfo.exclusiveStartKey));
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to serialize exclusiveStartKey", e);
}
}
// offset.put(EXCLUSIVE_START_KEY, gson.toJson(sourceInfo.exclusiveStartKey));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void start(AmazonDynamoDB dynamoDBClient,
String tableName,
String taskid,
String endpoint,
String tableVersion,
BillingMode kclTablebillingMode);

void stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public void start(AmazonDynamoDB dynamoDBClient,
String tableName,
String taskid,
String endpoint,
String tableVersion,
BillingMode kclTableBillingMode) {
IRecordProcessorFactory recordProcessorFactory = new KclRecordProcessorFactory(tableName, eventsQueue,
recordProcessorsRegister);

KinesisClientLibConfiguration clientLibConfiguration = getClientLibConfiguration(tableName,
taskid,
dynamoDBClient, endpoint, kclTableBillingMode);
dynamoDBClient, endpoint, tableVersion, kclTableBillingMode);

AmazonDynamoDBStreamsAdapterClient adapterClient = new AmazonDynamoDBStreamsAdapterClient(dynamoDBStreamsClient);

Expand Down Expand Up @@ -123,12 +124,17 @@ KinesisClientLibConfiguration getClientLibConfiguration(String tableName,
String taskid,
AmazonDynamoDB dynamoDBClient,
String endpoint,
String tableVersion,
BillingMode kclTableBillingMode) {

String streamArn = dynamoDBClient.describeTable(
new DescribeTableRequest()
.withTableName(tableName)).getTable().getLatestStreamArn();

if (tableVersion != null && !tableVersion.isEmpty()) {
tableName = tableName + "-" + tableVersion;
}

return new KinesisClientLibConfiguration(
Constants.KCL_WORKER_APPLICATION_NAME_PREFIX + tableName,
streamArn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public void kclWorkerIsStartedOnStart() throws InterruptedException {
eq(tableName),
eq("testTask1"),
eq(null),
eq(""),
eq(BillingMode.PROVISIONED)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void initializationRegistersNewShardToRegistry() {
when(dynamoDBClient.describeTable(ArgumentMatchers.<DescribeTableRequest>any())).thenReturn(result);

// Act
KinesisClientLibConfiguration clientLibConfiguration = kclWorker.getClientLibConfiguration(tableName, taskId, dynamoDBClient, serviceEndpoint, kclTableBillingMode);
KinesisClientLibConfiguration clientLibConfiguration = kclWorker.getClientLibConfiguration(tableName, taskId, dynamoDBClient, serviceEndpoint, "", kclTableBillingMode);

// Assert
assertEquals("datalake-KCL-testTableName1", clientLibConfiguration.getApplicationName());
Expand Down