-
Notifications
You must be signed in to change notification settings - Fork 37
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
Add upgrade()
to Admin API
#1204
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -647,6 +647,33 @@ public Set<String> getNamespaceNames() throws ExecutionException { | |
} | ||
} | ||
|
||
@Override | ||
public void upgrade(Map<String, String> options) throws ExecutionException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
try { | ||
if (!tableMetadataContainerExists()) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just quick silly questions.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may be a misunderstanding here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this answer your question ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! Understood 👍 |
||
} | ||
createMetadataDatabaseAndNamespaceContainerIfNotExists(); | ||
|
||
// Upsert namespace of existing tables in the "namespaces" container | ||
getTableMetadataContainer() | ||
.queryItems( | ||
"SELECT container.id FROM container", | ||
new CosmosQueryRequestOptions(), | ||
CosmosTableMetadata.class) | ||
.stream() | ||
.map( | ||
tableMetadata -> | ||
tableMetadata.getId().substring(0, tableMetadata.getId().indexOf('.'))) | ||
.distinct() | ||
.forEach( | ||
namespaceName -> | ||
getNamespacesContainer().upsertItem(new CosmosNamespace(namespaceName))); | ||
} catch (RuntimeException e) { | ||
throw new ExecutionException("Upgrading the ScalarDB environemnt failed", e); | ||
} | ||
} | ||
|
||
private void createMetadataDatabaseAndNamespaceContainerIfNotExists() { | ||
ThroughputProperties manualThroughput = | ||
ThroughputProperties.createManualThroughput(Integer.parseInt(DEFAULT_REQUEST_UNIT)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1363,6 +1363,50 @@ public Set<String> getNamespaceNames() throws ExecutionException { | |
} | ||
} | ||
|
||
@Override | ||
public void upgrade(Map<String, String> options) throws ExecutionException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
if (!metadataTableExists()) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar question to the above one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My answer is the same as #1204 (comment) |
||
} | ||
boolean noBackup = Boolean.parseBoolean(options.getOrDefault(NO_BACKUP, DEFAULT_NO_BACKUP)); | ||
createNamespacesTableIfNotExists(noBackup); | ||
try { | ||
for (Namespace namespace : getNamespacesOfExistingTables()) { | ||
upsertIntoNamespacesTable(namespace); | ||
} | ||
} catch (ExecutionException e) { | ||
throw new ExecutionException("Upgrading the ScalarDB environment failed", e); | ||
} | ||
} | ||
|
||
private Set<Namespace> getNamespacesOfExistingTables() throws ExecutionException { | ||
Set<Namespace> namespaceNames = new HashSet<>(); | ||
Map<String, AttributeValue> lastEvaluatedKey = null; | ||
do { | ||
ScanResponse scanResponse; | ||
try { | ||
scanResponse = | ||
client.scan( | ||
ScanRequest.builder() | ||
.tableName(ScalarDbUtils.getFullTableName(metadataNamespace, METADATA_TABLE)) | ||
.exclusiveStartKey(lastEvaluatedKey) | ||
.build()); | ||
} catch (RuntimeException e) { | ||
throw new ExecutionException( | ||
"Failed to retrieve the namespaces names of existing tables", e); | ||
} | ||
lastEvaluatedKey = scanResponse.lastEvaluatedKey(); | ||
|
||
for (Map<String, AttributeValue> tableMetadata : scanResponse.items()) { | ||
String fullTableName = tableMetadata.get(METADATA_ATTR_TABLE).s(); | ||
String namespaceName = fullTableName.substring(0, fullTableName.indexOf('.')); | ||
namespaceNames.add(Namespace.of(namespaceName)); | ||
} | ||
} while (!lastEvaluatedKey.isEmpty()); | ||
|
||
return namespaceNames; | ||
} | ||
|
||
private void createNamespacesTableIfNotExists(boolean noBackup) throws ExecutionException { | ||
try { | ||
if (!namespacesTableExists()) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
upgrade()
implementation of theCassandraAdmin