smiklosovic commented on a change in pull request #1046: URL: https://github.com/apache/cassandra/pull/1046#discussion_r678392449
########## File path: src/java/org/apache/cassandra/service/snapshot/TableSnapshotDetails.java ########## @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.service.snapshot; + +import java.io.File; +import java.time.Instant; +import java.util.Objects; +import java.util.Set; +import java.util.function.Function; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.db.ColumnFamilyStore; +import org.apache.cassandra.db.Directories; +import org.apache.cassandra.db.Keyspace; +import org.apache.cassandra.io.util.FileUtils; +import org.apache.cassandra.schema.Schema; +import org.apache.cassandra.service.StorageService; + +public class TableSnapshotDetails +{ + private final String keyspace; + private final String table; + private final String tag; + + private final Instant createdAt; + private final Instant expiresAt; + + private final Set<File> snapshotDirs; + private final Function<File, Long> trueDiskSizeComputer; + private boolean deleted; + + public TableSnapshotDetails(String keyspace, String table, String tag, SnapshotManifest manifest, + Set<File> snapshotDirs, Function<File, Long> trueDiskSizeComputer) + { + this.keyspace = keyspace; + this.table = table; + this.tag = tag; + this.createdAt = manifest == null ? null : manifest.createdAt; + this.expiresAt = manifest == null ? null : manifest.expiresAt; + this.snapshotDirs = snapshotDirs; + this.trueDiskSizeComputer = trueDiskSizeComputer; + } + + public String getKeyspace() + { + return keyspace; + } + + public String getTable() + { + return table; + } + + public String getTag() + { + return tag; + } + + public Instant getCreatedAt() + { + return createdAt; + } + + public Instant getExpiresAt() + { + return expiresAt; + } + + public boolean isExpired(Instant now) { + if (createdAt == null || expiresAt == null) { + return false; + } + + return expiresAt.compareTo(now) < 0; + } + + public boolean isDeleted() { + return deleted; + } + + public boolean isExpiring() { + return expiresAt != null; + } + + public long computeSizeOnDiskBytes() + { + return snapshotDirs.stream().mapToLong(FileUtils::folderSize).sum(); + } + + public long computeTrueSizeBytes() + { + return snapshotDirs.stream().mapToLong(trueDiskSizeComputer::apply).sum(); + } + + public void deleteSnapshot() Review comment: I dont like this method located here. This class should be more or less just a simple POJO, no logic. -- 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]

