sashapolo commented on a change in pull request #468: URL: https://github.com/apache/ignite-3/pull/468#discussion_r766743157
########## File path: modules/storage-rocksdb/src/main/java/org/apache/ignite/internal/storage/rocksdb/index/RocksDbSortedIndexStorage.java ########## @@ -0,0 +1,148 @@ +/* + * 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.ignite.internal.storage.rocksdb.index; + +import org.apache.ignite.internal.rocksdb.ColumnFamily; +import org.apache.ignite.internal.rocksdb.RocksIteratorAdapter; +import org.apache.ignite.internal.schema.ByteBufferRow; +import org.apache.ignite.internal.storage.StorageException; +import org.apache.ignite.internal.storage.index.IndexRow; +import org.apache.ignite.internal.storage.index.IndexRowDeserializer; +import org.apache.ignite.internal.storage.index.IndexRowFactory; +import org.apache.ignite.internal.storage.index.IndexRowPrefix; +import org.apache.ignite.internal.storage.index.SortedIndexDescriptor; +import org.apache.ignite.internal.storage.index.SortedIndexStorage; +import org.apache.ignite.internal.util.Cursor; +import org.jetbrains.annotations.Nullable; +import org.rocksdb.RocksDBException; +import org.rocksdb.RocksIterator; + +/** + * {@link SortedIndexStorage} implementation based on RocksDB. + */ +public class RocksDbSortedIndexStorage implements SortedIndexStorage { + private final ColumnFamily indexCf; + + private final SortedIndexDescriptor descriptor; + + private final IndexRowFactory indexRowFactory; + + private final IndexRowDeserializer indexRowDeserializer; + + /** + * Creates a new Index storage. + * + * @param indexCf Column Family for storing the data. + * @param descriptor Index descriptor. + */ + public RocksDbSortedIndexStorage(ColumnFamily indexCf, SortedIndexDescriptor descriptor) { + this.indexCf = indexCf; + this.descriptor = descriptor; + this.indexRowFactory = new BinaryIndexRowFactory(descriptor); + this.indexRowDeserializer = new BinaryIndexRowDeserializer(descriptor); + } + + @Override + public SortedIndexDescriptor indexDescriptor() { + return descriptor; + } + + @Override + public IndexRowFactory indexKeyFactory() { + return indexRowFactory; + } + + @Override + public IndexRowDeserializer indexRowDeserializer() { + return indexRowDeserializer; + } + + @Override + public void put(IndexRow row) { + try { + indexCf.put(row.rowBytes(), row.primaryKey().keyBytes()); + } catch (RocksDBException e) { + throw new StorageException("Error while adding data to Rocks DB", e); + } + } + + @Override + public void remove(IndexRow key) { + try { + indexCf.delete(key.rowBytes()); + } catch (RocksDBException e) { + throw new StorageException("Error while removing data from Rocks DB", e); + } + } + + @Override + public Cursor<IndexRow> range(IndexRowPrefix lowerBound, IndexRowPrefix upperBound) { + RocksIterator iter = indexCf.newIterator(); + + iter.seekToFirst(); Review comment: Unfortunately, no. `BinaryRow` serialization places columns differently than specified in the schema. This means that some column, that is missing in the prefix, can actually be the first bytes of the serialized row. What I'm trying to say is that some prefix column values might not serialize as a byte prefix of the serialized row =( -- 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]
