LuciferYang commented on a change in pull request #34913: URL: https://github.com/apache/spark/pull/34913#discussion_r770266189
########## File path: common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java ########## @@ -0,0 +1,436 @@ +/* + * 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.spark.util.kvstore; + +import java.io.File; +import java.io.IOException; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; +import org.rocksdb.BlockBasedTableConfig; +import org.rocksdb.Options; +import org.rocksdb.Statistics; +import org.rocksdb.WriteBatch; +import org.rocksdb.WriteOptions; + +import org.apache.spark.annotation.Private; + +/** + * Implementation of KVStore that uses RocksDB as the underlying data store. + */ +@Private +public class RocksDB implements KVStore { + + static { + org.rocksdb.RocksDB.loadLibrary(); + } + + @VisibleForTesting + static final long STORE_VERSION = 1L; + + @VisibleForTesting + static final byte[] STORE_VERSION_KEY = "__version__".getBytes(UTF_8); + + /** DB key where app metadata is stored. */ + private static final byte[] METADATA_KEY = "__meta__".getBytes(UTF_8); + + /** DB key where type aliases are stored. */ + private static final byte[] TYPE_ALIASES_KEY = "__types__".getBytes(UTF_8); + + private static final BlockBasedTableConfig tableFormatConfig = new BlockBasedTableConfig() + .setFormatVersion(5); + + private static final Options dbOptions = new Options() + .setCreateIfMissing(true) + .setTableFormatConfig(tableFormatConfig) + .setStatistics(new Statistics()); + + private static final WriteOptions writeOptions = new WriteOptions().setSync(true); + + private AtomicReference<org.rocksdb.RocksDB> _db; Review comment: Should `_db` be identified as `final`? It is assigned only once -- 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]
