frankgh commented on code in PR #4100:
URL: https://github.com/apache/cassandra/pull/4100#discussion_r2072011490
##########
src/java/org/apache/cassandra/service/snapshot/SnapshotOptions.java:
##########
@@ -214,7 +224,7 @@ public SnapshotOptions build()
if (rateLimiter == null)
rateLimiter = DatabaseDescriptor.getSnapshotRateLimiter();
- return new SnapshotOptions(type, tag, ttl, creationTime,
skipFlush, ephemeral, entities, rateLimiter,
+ return new SnapshotOptions(type, tag, ttl, creationTime,
skipFlush, ephemeral, force, entities, rateLimiter,
Review Comment:
NIT, maybe just pass the builder instead?
```suggestion
return new SnapshotOptions(this);
```
and the constructor will look like this:
```
private SnapshotOptions(Builder builder)
{
this.type = builder.type;
this.tag = builder.tag;
this.ttl = builder.ttl;
this.creationTime = builder.creationTime;
this.skipFlush = builder.skipFlush;
this.ephemeral = builder.ephemeral;
this.force = builder.force;
this.entities = builder.entities;
this.rateLimiter = builder.rateLimiter;
this.sstableFilter = builder.sstableFilter;
this.cfs = builder.cfs;
}
```
##########
src/java/org/apache/cassandra/service/snapshot/SnapshotManager.java:
##########
@@ -568,18 +570,33 @@ <T> T executeTask(AbstractSnapshotTask<T> task)
private synchronized void prePopulateSnapshots(TakeSnapshotTask task)
{
Map<ColumnFamilyStore, TableSnapshot> snapshotsToCreate =
task.getSnapshotsToCreate();
- for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry :
snapshotsToCreate.entrySet())
+ Map<ColumnFamilyStore, TableSnapshot> snapshotsToOverwrite = new
HashMap<>();
+ List<TableSnapshot> toCreate = new
ArrayList<>(snapshotsToCreate.values());
+
+ for (TableSnapshot existingSnapshot : snapshots)
{
- if (snapshots.contains(toCreateEntry.getValue()))
+ for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry :
snapshotsToCreate.entrySet())
{
- throw new RuntimeException(format("Snapshot %s for %s.%s
already exists.",
-
toCreateEntry.getValue().getTag(),
-
toCreateEntry.getValue().getKeyspaceName(),
-
toCreateEntry.getValue().getTableName()));
+ TableSnapshot snapshotToCreate = toCreateEntry.getValue();
+ if (existingSnapshot.equals(toCreateEntry.getValue()))
+ {
+ if (!task.options.force)
+ {
+ throw new RuntimeException(format("Snapshot %s for
%s.%s already exists.",
+
snapshotToCreate.getTag(),
+
snapshotToCreate.getKeyspaceName(),
+
snapshotToCreate.getTableName()));
+ }
+
+ toCreate.remove(toCreateEntry.getValue());
Review Comment:
```suggestion
toCreate.remove(snapshotToCreate);
```
##########
src/java/org/apache/cassandra/service/snapshot/SnapshotManager.java:
##########
@@ -568,18 +570,33 @@ <T> T executeTask(AbstractSnapshotTask<T> task)
private synchronized void prePopulateSnapshots(TakeSnapshotTask task)
{
Map<ColumnFamilyStore, TableSnapshot> snapshotsToCreate =
task.getSnapshotsToCreate();
- for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry :
snapshotsToCreate.entrySet())
+ Map<ColumnFamilyStore, TableSnapshot> snapshotsToOverwrite = new
HashMap<>();
+ List<TableSnapshot> toCreate = new
ArrayList<>(snapshotsToCreate.values());
+
+ for (TableSnapshot existingSnapshot : snapshots)
{
- if (snapshots.contains(toCreateEntry.getValue()))
+ for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry :
snapshotsToCreate.entrySet())
{
- throw new RuntimeException(format("Snapshot %s for %s.%s
already exists.",
-
toCreateEntry.getValue().getTag(),
-
toCreateEntry.getValue().getKeyspaceName(),
-
toCreateEntry.getValue().getTableName()));
+ TableSnapshot snapshotToCreate = toCreateEntry.getValue();
+ if (existingSnapshot.equals(toCreateEntry.getValue()))
Review Comment:
```suggestion
if (existingSnapshot.equals(snapshotToCreate))
```
##########
src/java/org/apache/cassandra/service/snapshot/SnapshotManager.java:
##########
@@ -568,18 +570,33 @@ <T> T executeTask(AbstractSnapshotTask<T> task)
private synchronized void prePopulateSnapshots(TakeSnapshotTask task)
{
Map<ColumnFamilyStore, TableSnapshot> snapshotsToCreate =
task.getSnapshotsToCreate();
- for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry :
snapshotsToCreate.entrySet())
+ Map<ColumnFamilyStore, TableSnapshot> snapshotsToOverwrite = new
HashMap<>();
Review Comment:
I don't really see any actual usage of snapshotsToOverwite. You populate it
in the iteration and then add it to snapshotsToCreate after the iteration, but
then the snapshotsToCreate is no longer used. So it seems we can remove this
map.
Also, I think we should update the javadoc of this method to reflect the new
behavior
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]