maedhroz commented on code in PR #254: URL: https://github.com/apache/cassandra-analytics/pull/254#discussion_r4406323659
########## cassandra-five-zero/src/main/java/org/apache/cassandra/index/sai/disk/format/IndexDescriptor.java: ########## @@ -0,0 +1,608 @@ +/* + * 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.index.sai.disk.format; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Set; +import java.util.stream.Collectors; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Objects; +import com.google.common.io.Files; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.cassandra.db.ClusteringComparator; +import org.apache.cassandra.db.lifecycle.LifecycleNewTracker; +import org.apache.cassandra.dht.IPartitioner; +import org.apache.cassandra.index.sai.IndexValidation; +import org.apache.cassandra.index.sai.SSTableContext; +import org.apache.cassandra.index.sai.StorageAttachedIndex; +import org.apache.cassandra.index.sai.disk.EmptyIndex; +import org.apache.cassandra.index.sai.disk.PerColumnIndexWriter; +import org.apache.cassandra.index.sai.disk.PerSSTableIndexWriter; +import org.apache.cassandra.index.sai.disk.PrimaryKeyMap; +import org.apache.cassandra.index.sai.disk.RowMapping; +import org.apache.cassandra.index.sai.disk.SSTableIndex; +import org.apache.cassandra.index.sai.disk.io.IndexFileUtils; +import org.apache.cassandra.index.sai.disk.io.IndexInputReader; +import org.apache.cassandra.index.sai.disk.io.IndexOutputWriter; +import org.apache.cassandra.index.sai.utils.IndexIdentifier; +import org.apache.cassandra.index.sai.utils.IndexTermType; +import org.apache.cassandra.index.sai.utils.PrimaryKey; +import org.apache.cassandra.io.sstable.Component; +import org.apache.cassandra.io.sstable.Descriptor; +import org.apache.cassandra.io.sstable.format.SSTableReader; +import org.apache.cassandra.io.util.File; +import org.apache.cassandra.io.util.FileHandle; +import org.apache.cassandra.utils.FBUtilities; +import org.apache.cassandra.utils.Throwables; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.util.IOUtils; + +/** + * NOTE: This copy is based on Cassandra 5.0.7 and adds {@link FileAccess} so Cassandra Analytics can + * read SAI components through Cassandra Sidecar without materializing them on local disk. + * <p> + * The {@link IndexDescriptor} is an analog of the SSTable {@link Descriptor} and provides version + * specific information about the on-disk state of a {@link StorageAttachedIndex}. + * <p> + * The {@link IndexDescriptor} is primarily responsible for maintaining a view of the on-disk state + * of an index for a specific {@link org.apache.cassandra.io.sstable.SSTable}. + * <p> + * It is responsible for opening files for use by writers and readers. + * <p> + * Its remaining responsibility is to act as a proxy to the {@link OnDiskFormat} associated with the + * index {@link Version}. + */ +public class IndexDescriptor +{ + private static final Logger logger = LoggerFactory.getLogger(IndexDescriptor.class); + + public final Version version; + public final Descriptor sstableDescriptor; + public final ClusteringComparator clusteringComparator; + public final PrimaryKey.Factory primaryKeyFactory; + + private final FileAccess fileAccess; + + /** + * Read-only access to SAI components that are not backed by the local filesystem. + * Writers continue to use the regular Cassandra filesystem path. + */ + public interface FileAccess + { + boolean exists(File file); + + long length(File file); + + FileHandle open(File file); + } Review Comment: At first glance, having two full duplicates of `IndexDescriptor` here seems unfortunate. Why not just add the `FileAccess` interface to the upstream `IndexDescriptor` classes (and change the static factories accordingly)? I guess we could also make the `IndexDescriptor` constructor `protected`, but the first option seems better... -- 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]
