Builds RocksDb {@link Options}.

@param maxBackgroundThreads
@param levelZeloFileNumCompactionTrigger
@param writeBufferSize
@param targetFileSizeBase
@return
351894
public static Options buildOptions(int maxBackgroundThreads,
            int levelZeloFileNumCompactionTrigger, long writeBufferSize, long targetFileSizeBase) {
        Options rocksOptions = new Options();
        rocksOptions.setCreateIfMissing(true).getEnv().setBackgroundThreads(1, Env.FLUSH_POOL)
                .setBackgroundThreads(maxBackgroundThreads, Env.COMPACTION_POOL);
        rocksOptions.setMaxBackgroundFlushes(1).setMaxBackgroundCompactions(maxBackgroundThreads);
        rocksOptions.setWriteBufferSize(writeBufferSize).setMinWriteBufferNumberToMerge(2)
                .setLevelZeroFileNumCompactionTrigger(levelZeloFileNumCompactionTrigger)
                .setTargetFileSizeBase(targetFileSizeBase);

        rocksOptions.setMemTableConfig(new SkipListMemTableConfig());
        // rocksOptions.setMemTableConfig(new HashSkipListMemTableConfig());
        // rocksOptions.setMemTableConfig(new HashLinkedListMemTableConfig());

        return rocksOptions;
    }
275942
@Override
    public int executeBatch()
    {
        Map<String, BulkWriteOperation> bulkWriteOperationMap = new HashMap<String, BulkWriteOperation>();
        int size = 0;
        for (Node node : nodes)
        {
            if (node.isDirty())
            {
                node.handlePreEvent();
                // delete can not be executed in batch
                if (node.isInState(RemovedState.class))
                {
                    delete(node.getData(), node.getEntityId());
                }
                else
                {
                    List<RelationHolder> relationHolders = getRelationHolders(node);
                    EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                            node.getDataClass());
                    Map<String, DBObject> documents = handler.getDocumentFromEntity(metadata, node.getData(),
                            relationHolders, kunderaMetadata);
                    for (String tableName : documents.keySet())
                    {
                        if (!bulkWriteOperationMap.containsKey(tableName))
                        {
                            DBCollection collection = mongoDb.getCollection(tableName);
                            BulkWriteOperation builder = null;
                            if (isOrderedBulkOperation())
                            {
                                builder = collection.initializeOrderedBulkOperation();
                            }
                            else
                            {
                                builder = collection.initializeUnorderedBulkOperation();
                            }
                            bulkWriteOperationMap.put(tableName, builder);
                        }

                        if (!node.isUpdate())
                        {
                            bulkWriteOperationMap.get(tableName).insert(documents.get(tableName));
                        }

                        else
                        {
                            bulkWriteOperationMap.get(tableName).find(new BasicDBObject("_id", node.getEntityId()))
                                    .upsert().replaceOne(documents.get(tableName));
                        }
                        size++;
                    }
                    indexNode(node, metadata);
                }
                node.handlePostEvent();
            }
        }
        onFlushBatch(bulkWriteOperationMap);
        return size;
    }
924699
function _writeBufferToPort(buffer, transactionId) {
    var transaction = this._transactions[transactionId];

    this._port.write(buffer);
    if (transaction) {
        transaction._timeoutFired = false;
        transaction._timeoutHandle = _startTimeout(this._timeout, transaction);
    }
}
782249
private static void writeFile(CyclicBarrier barrier, AtomicLong runtime, int count,
      AlluxioConfiguration alluxioConf)
      throws Exception {
    FileSystem fileSystem = FileSystem.Factory.create(alluxioConf);
    byte[] buffer = new byte[(int) Math.min(sFileSize, 4 * Constants.MB)];
    Arrays.fill(buffer, (byte) 'a');
    AlluxioURI path = filename(count);

    if (fileSystem.exists(path)) {
      fileSystem.delete(path);
    }

    barrier.await();
    long startTime = System.nanoTime();
    long bytesWritten = 0;
    try (FileOutStream outStream = fileSystem.createFile(path)) {
      while (bytesWritten < sFileSize) {
        outStream.write(buffer, 0, (int) Math.min(buffer.length, sFileSize - bytesWritten));
        bytesWritten += buffer.length;
      }
    }
    runtime.addAndGet(System.nanoTime() - startTime);
  }
928785
public void setMaxBatchSize(final String maxBatchSize) {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled()) {
            SibTr.debug(this, TRACE, "MaxBatchSize", maxBatchSize);
        }
        _maxBatchSize = (maxBatchSize == null ? null : Integer.valueOf(maxBatchSize));

    }
137164
public ISynchronizationPoint<Exception> compress(Readable input, Writable output, int bufferSize, int maxBuffers, byte priority) {
		Deflater deflater = new Deflater(level, nowrap);
		LimitWriteOperationsReuseBuffers limit = new LimitWriteOperationsReuseBuffers(output, bufferSize, maxBuffers);
		byte[] bufRead = new byte[bufferSize];
		ByteBuffer buffer = ByteBuffer.wrap(bufRead);
		AsyncWork<Integer,IOException> task = input.readAsync(buffer);
		SynchronizationPoint<Exception> end = new SynchronizationPoint<>();
		task.listenAsync(new Compress(input, output, task, bufRead, deflater, limit, priority, end), true);
		return end;
	}
274863
protected void buildCache(int maxCacheSize) {
        if (blackPrefixList != null && !blackPrefixList.isEmpty()) {
            int min = Math.min(256, maxCacheSize);
            int max = Math.min(10240, maxCacheSize);
            ConcurrentLinkedHashMap.Builder<String, Boolean> builder = new ConcurrentLinkedHashMap.Builder<String, Boolean>()
                .initialCapacity(min).maximumWeightedCapacity(max);
            this.resultOfInBlackList = builder.build();
        } else {
            this.resultOfInBlackList = null;
        }
    }
903037
public <K, V> SortingBufferMaker<K, V> createSortingBuffer( BTreeKeySerializer<K> keySerializer,
                                                                Serializer<V> valueSerializer ) {
        return new MakeSortingBuffer<K, V>("buffer-" + dbCounter.incrementAndGet(), keySerializer, valueSerializer);
    }
993984
@SuppressWarnings("static-access")
    private static synchronized Options buildOptions() {
        Options options = new Options();
        options.addOption(OptionBuilder.hasArg().withArgName("path").withDescription("Specify where to find the class files - must be first argument").create("classpath"));
        options.addOption(OptionBuilder.withLongOpt("classpath").hasArg().withArgName("path").withDescription("Aliases for '-classpath'").create("cp"));

        options.addOption(
            OptionBuilder.withLongOpt("define").
            withDescription("define a system property").
            hasArg(true).
            withArgName("name=value").
            create('D'));
        options.addOption(
            OptionBuilder.withLongOpt("disableopt").
            withDescription("disables one or all optimization elements. " +
                            "optlist can be a comma separated list with the elements: " +
                            "all (disables all optimizations), " +
                            "int (disable any int based optimizations)").
            hasArg(true).
            withArgName("optlist").
            create());
        options.addOption(
            OptionBuilder.hasArg(false)
            .withDescription("usage information")
            .withLongOpt("help")
            .create('h'));
        options.addOption(
            OptionBuilder.hasArg(false)
            .withDescription("debug mode will print out full stack traces")
            .withLongOpt("debug")
            .create('d'));
        options.addOption(
            OptionBuilder.hasArg(false)
            .withDescription("display the Groovy and JVM versions")
            .withLongOpt("version")
            .create('v'));
        options.addOption(
            OptionBuilder.withArgName("charset")
            .hasArg()
            .withDescription("specify the encoding of the files")
            .withLongOpt("encoding")
            .create('c'));
        options.addOption(
            OptionBuilder.withArgName("script")
            .hasArg()
            .withDescription("specify a command line script")
            .create('e'));
        options.addOption(
            OptionBuilder.withArgName("extension")
            .hasOptionalArg()
            .withDescription("modify files in place; create backup if extension is given (e.g. \'.bak\')")
            .create('i'));
        options.addOption(
            OptionBuilder.hasArg(false)
            .withDescription("process files line by line using implicit 'line' variable")
            .create('n'));
        options.addOption(
            OptionBuilder.hasArg(false)
            .withDescription("process files line by line and print result (see also -n)")
            .create('p'));
        options.addOption(
            OptionBuilder.withArgName("port")
            .hasOptionalArg()
            .withDescription("listen on a port and process inbound lines (default: 1960)")
            .create('l'));
        options.addOption(
            OptionBuilder.withArgName("splitPattern")
            .hasOptionalArg()
            .withDescription("split lines using splitPattern (default '\\s') using implicit 'split' variable")
            .withLongOpt("autosplit")
            .create('a'));
        options.addOption(
            OptionBuilder.withLongOpt("indy")
            .withDescription("enables compilation using invokedynamic")
            .create());
        options.addOption(
            OptionBuilder.withLongOpt("configscript")
            .hasArg().withDescription("A script for tweaking the configuration options")
            .create());
        options.addOption(
                OptionBuilder.withLongOpt("basescript")
                .hasArg().withArgName("class").withDescription("Base class name for scripts (must derive from Script)")
                .create('b'));
        return options;

    }
216181
@Override
  public DatanodeDescriptor[] chooseTarget(FSInodeInfo srcInode,
      int numOfReplicas,
      DatanodeDescriptor writer, List<DatanodeDescriptor> chosenNodes,
      List<Node> excludesNodes, long blocksize) {
    if (numOfReplicas == 0 || clusterMap.getNumOfLeaves() == 0) {
      return new DatanodeDescriptor[0];
    }

    int[] result = getActualReplicas(numOfReplicas, chosenNodes);
    numOfReplicas = result[0];
    int maxNodesPerRack = result[1];

    HashMap<Node, Node> excludedNodes = new HashMap<Node, Node>();
    List<DatanodeDescriptor> results = new ArrayList<DatanodeDescriptor>(
        chosenNodes.size() + numOfReplicas);

    updateExcludedAndChosen(null, excludedNodes, results, chosenNodes);

    if (!clusterMap.contains(writer)) {
      writer = null;
    }

    DatanodeDescriptor localNode = super.chooseTarget(numOfReplicas, writer,
        excludedNodes, blocksize, maxNodesPerRack, results,
        chosenNodes.isEmpty());

    return this.finalizeTargets(results, chosenNodes, writer, localNode);
  }
809958
public Uploader startUploadFileChunked(int chunkSize, String targetPath, DbxWriteMode writeMode, long numBytes)
    {
        DbxPathV1.checkArg("targetPath", targetPath);
        if (writeMode == null) throw new IllegalArgumentException("'writeMode' can't be null");

        return new ChunkedUploader(targetPath, writeMode, numBytes, new ChunkedUploadOutputStream(chunkSize));
    }
996062
private void init(int maxPoolSize)
   {
      this.maxPoolSize = maxPoolSize;

      this.createdCount = new AtomicInteger(0);
      this.destroyedCount = new AtomicInteger(0);
      this.maxCreationTime = new AtomicLong(Long.MIN_VALUE);
      this.maxGetTime = new AtomicLong(Long.MIN_VALUE);
      this.maxPoolTime = new AtomicLong(Long.MIN_VALUE);
      this.maxUsageTime = new AtomicLong(Long.MIN_VALUE);
      this.maxUsedCount = new AtomicInteger(Integer.MIN_VALUE);
      this.maxWaitCount = new AtomicInteger(0);
      this.maxWaitTime = new AtomicLong(Long.MIN_VALUE);
      this.timedOut = new AtomicInteger(0);
      this.totalBlockingTime = new AtomicLong(0);
      this.totalBlockingTimeInvocations = new AtomicLong(0);
      this.totalCreationTime = new AtomicLong(0);
      this.totalGetTime = new AtomicLong(0);
      this.totalGetTimeInvocations = new AtomicLong(0);
      this.totalPoolTime = new AtomicLong(0);
      this.totalPoolTimeInvocations = new AtomicLong(0);
      this.totalUsageTime = new AtomicLong(0);
      this.totalUsageTimeInvocations = new AtomicLong(0);
      this.inUseCount = new AtomicInteger(0);
      this.blockingFailureCount = new AtomicInteger(0);
      this.waitCount = new AtomicInteger(0);

      this.commitCount = new AtomicLong(0L);
      this.commitTotalTime = new AtomicLong(0L);
      this.commitMaxTime = new AtomicLong(0L);
      this.endCount = new AtomicLong(0L);
      this.endTotalTime = new AtomicLong(0L);
      this.endMaxTime = new AtomicLong(0L);
      this.forgetCount = new AtomicLong(0L);
      this.forgetTotalTime = new AtomicLong(0L);
      this.forgetMaxTime = new AtomicLong(0L);
      this.prepareCount = new AtomicLong(0L);
      this.prepareTotalTime = new AtomicLong(0L);
      this.prepareMaxTime = new AtomicLong(0L);
      this.recoverCount = new AtomicLong(0L);
      this.recoverTotalTime = new AtomicLong(0L);
      this.recoverMaxTime = new AtomicLong(0L);
      this.rollbackCount = new AtomicLong(0L);
      this.rollbackTotalTime = new AtomicLong(0L);
      this.rollbackMaxTime = new AtomicLong(0L);
      this.startCount = new AtomicLong(0L);
      this.startTotalTime = new AtomicLong(0L);
      this.startMaxTime = new AtomicLong(0L);

      SortedSet<String> n = new TreeSet<String>();
      Map<String, Class> t = new HashMap<String, Class>();

      n.add(ACTIVE_COUNT);
      t.put(ACTIVE_COUNT, int.class);

      n.add(AVAILABLE_COUNT);
      t.put(AVAILABLE_COUNT, int.class);

      n.add(AVERAGE_BLOCKING_TIME);
      t.put(AVERAGE_BLOCKING_TIME, long.class);

      n.add(AVERAGE_CREATION_TIME);
      t.put(AVERAGE_CREATION_TIME, long.class);

      n.add(AVERAGE_GET_TIME);
      t.put(AVERAGE_GET_TIME, long.class);

      n.add(AVERAGE_USAGE_TIME);
      t.put(AVERAGE_USAGE_TIME, long.class);

      n.add(AVERAGE_POOL_TIME);
      t.put(AVERAGE_POOL_TIME, long.class);

      n.add(BLOCKING_FAILURE_COUNT);
      t.put(BLOCKING_FAILURE_COUNT, int.class);

      n.add(CREATED_COUNT);
      t.put(CREATED_COUNT, int.class);

      n.add(DESTROYED_COUNT);
      t.put(DESTROYED_COUNT, int.class);

      n.add(IDLE_COUNT);
      t.put(IDLE_COUNT, int.class);

      n.add(IN_USE_COUNT);
      t.put(IN_USE_COUNT, int.class);

      n.add(MAX_CREATION_TIME);
      t.put(MAX_CREATION_TIME, long.class);

      n.add(MAX_GET_TIME);
      t.put(MAX_GET_TIME, long.class);

      n.add(MAX_POOL_TIME);
      t.put(MAX_POOL_TIME, long.class);

      n.add(MAX_USAGE_TIME);
      t.put(MAX_USAGE_TIME, long.class);

      n.add(MAX_USED_COUNT);
      t.put(MAX_USED_COUNT, int.class);

      n.add(MAX_WAIT_COUNT);
      t.put(MAX_WAIT_COUNT, int.class);

      n.add(MAX_WAIT_TIME);
      t.put(MAX_WAIT_TIME, long.class);

      n.add(TIMED_OUT);
      t.put(TIMED_OUT, int.class);

      n.add(TOTAL_BLOCKING_TIME);
      t.put(TOTAL_BLOCKING_TIME, long.class);

      n.add(TOTAL_CREATION_TIME);
      t.put(TOTAL_CREATION_TIME, long.class);

      n.add(TOTAL_GET_TIME);
      t.put(TOTAL_GET_TIME, long.class);

      n.add(TOTAL_POOL_TIME);
      t.put(TOTAL_POOL_TIME, long.class);

      n.add(TOTAL_USAGE_TIME);
      t.put(TOTAL_USAGE_TIME, long.class);

      n.add(WAIT_COUNT);
      t.put(WAIT_COUNT, int.class);

      n.add(XA_COMMIT_COUNT);
      t.put(XA_COMMIT_COUNT, long.class);
      n.add(XA_COMMIT_AVERAGE_TIME);
      t.put(XA_COMMIT_AVERAGE_TIME, long.class);
      n.add(XA_COMMIT_TOTAL_TIME);
      t.put(XA_COMMIT_TOTAL_TIME, long.class);
      n.add(XA_COMMIT_MAX_TIME);
      t.put(XA_COMMIT_MAX_TIME, long.class);

      n.add(XA_END_COUNT);
      t.put(XA_END_COUNT, long.class);
      n.add(XA_END_AVERAGE_TIME);
      t.put(XA_END_AVERAGE_TIME, long.class);
      n.add(XA_END_TOTAL_TIME);
      t.put(XA_END_TOTAL_TIME, long.class);
      n.add(XA_END_MAX_TIME);
      t.put(XA_END_MAX_TIME, long.class);

      n.add(XA_FORGET_COUNT);
      t.put(XA_FORGET_COUNT, long.class);
      n.add(XA_FORGET_AVERAGE_TIME);
      t.put(XA_FORGET_AVERAGE_TIME, long.class);
      n.add(XA_FORGET_TOTAL_TIME);
      t.put(XA_FORGET_TOTAL_TIME, long.class);
      n.add(XA_FORGET_MAX_TIME);
      t.put(XA_FORGET_MAX_TIME, long.class);

      n.add(XA_PREPARE_COUNT);
      t.put(XA_PREPARE_COUNT, long.class);
      n.add(XA_PREPARE_AVERAGE_TIME);
      t.put(XA_PREPARE_AVERAGE_TIME, long.class);
      n.add(XA_PREPARE_TOTAL_TIME);
      t.put(XA_PREPARE_TOTAL_TIME, long.class);
      n.add(XA_PREPARE_MAX_TIME);
      t.put(XA_PREPARE_MAX_TIME, long.class);

      n.add(XA_RECOVER_COUNT);
      t.put(XA_RECOVER_COUNT, long.class);
      n.add(XA_RECOVER_AVERAGE_TIME);
      t.put(XA_RECOVER_AVERAGE_TIME, long.class);
      n.add(XA_RECOVER_TOTAL_TIME);
      t.put(XA_RECOVER_TOTAL_TIME, long.class);
      n.add(XA_RECOVER_MAX_TIME);
      t.put(XA_RECOVER_MAX_TIME, long.class);

      n.add(XA_ROLLBACK_COUNT);
      t.put(XA_ROLLBACK_COUNT, long.class);
      n.add(XA_ROLLBACK_AVERAGE_TIME);
      t.put(XA_ROLLBACK_AVERAGE_TIME, long.class);
      n.add(XA_ROLLBACK_TOTAL_TIME);
      t.put(XA_ROLLBACK_TOTAL_TIME, long.class);
      n.add(XA_ROLLBACK_MAX_TIME);
      t.put(XA_ROLLBACK_MAX_TIME, long.class);

      n.add(XA_START_COUNT);
      t.put(XA_START_COUNT, long.class);
      n.add(XA_START_AVERAGE_TIME);
      t.put(XA_START_AVERAGE_TIME, long.class);
      n.add(XA_START_TOTAL_TIME);
      t.put(XA_START_TOTAL_TIME, long.class);
      n.add(XA_START_MAX_TIME);
      t.put(XA_START_MAX_TIME, long.class);

      this.names = Collections.unmodifiableSortedSet(n);
      this.types = Collections.unmodifiableMap(t);
      this.enabled = new AtomicBoolean(true);
      
      ResourceBundle defaultResourceBundle = 
         ResourceBundle.getBundle("poolstatistics", Locale.US,
                                  SecurityActions.getClassLoader(PoolStatisticsImpl.class));
      this.rbs = new HashMap<Locale, ResourceBundle>(1);
      this.rbs.put(Locale.US, defaultResourceBundle);

      clear();
   }
937028
@Override
    public WsByteBuffer buildFrameForWrite() {

        WsByteBuffer[] output = buildFrameArrayForWrite();
        int size = 0;
        for (WsByteBuffer b : output) {
            if (b != null) {
                size += b.remaining();
            }
        }
        WsByteBuffer singleBuffer = this.getBuffer(size);
        singleBuffer.put(output);
        singleBuffer.flip();
        return singleBuffer;
    }
409034
@Override
    public void setWriteTarget(MessageWriteTarget writeTarget) {
        checkArgument(writeTarget != null);
        lock.lock();
        boolean closeNow = false;
        try {
            checkArgument(this.writeTarget == null);
            closeNow = closePending;
            this.writeTarget = writeTarget;
        } finally {
            lock.unlock();
        }
        if (closeNow)
            writeTarget.closeConnection();
    }
711115
@Override
    public void setMaxBatchSize(final Integer maxBatchSize) {
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled()) {
            SibTr.debug(this, TRACE, "setMaxBatchSize", maxBatchSize);
        }
        _maxBatchSize = maxBatchSize;
    }
905758
@Override
	public void dispose() {
		if (this.disposed) {
			return;
		}
		super.dispose();

		// This call will block until all clients that still acquire access to the RocksDB instance have released it,
		// so that we cannot release the native resources while clients are still working with it in parallel.
		rocksDBResourceGuard.close();

		// IMPORTANT: null reference to signal potential async checkpoint workers that the db was disposed, as
		// working on the disposed object results in SEGFAULTS.
		if (db != null) {

			IOUtils.closeQuietly(writeBatchWrapper);

			// Metric collection occurs on a background thread. When this method returns
			// it is guaranteed that thr RocksDB reference has been invalidated
			// and no more metric collection will be attempted against the database.
			if (nativeMetricMonitor != null) {
				nativeMetricMonitor.close();
			}

			List<ColumnFamilyOptions> columnFamilyOptions = new ArrayList<>(kvStateInformation.values().size());

			// RocksDB's native memory management requires that *all* CFs (including default) are closed before the
			// DB is closed. See:
			// https://github.com/facebook/rocksdb/wiki/RocksJava-Basics#opening-a-database-with-column-families
			// Start with default CF ...
			RocksDBOperationUtils.addColumnFamilyOptionsToCloseLater(columnFamilyOptions, defaultColumnFamily);
			IOUtils.closeQuietly(defaultColumnFamily);

			// ... continue with the ones created by Flink...
			for (RocksDbKvStateInfo kvStateInfo : kvStateInformation.values()) {
				RocksDBOperationUtils.addColumnFamilyOptionsToCloseLater(columnFamilyOptions, kvStateInfo.columnFamilyHandle);
				IOUtils.closeQuietly(kvStateInfo.columnFamilyHandle);
			}

			// ... and finally close the DB instance ...
			IOUtils.closeQuietly(db);

			columnFamilyOptions.forEach(IOUtils::closeQuietly);

			IOUtils.closeQuietly(dbOptions);
			IOUtils.closeQuietly(writeOptions);

			ttlCompactFiltersManager.disposeAndClearRegisteredCompactionFactories();

			kvStateInformation.clear();

			cleanInstanceBasePath();
		}
		this.disposed = true;
	}
1205075
def _commit_unless_raises(cls, write_target_db: BaseDB) -> Iterator['AtomicDBWriteBatch']:
        
        readable_write_batch = cls(write_target_db)     # type: AtomicDBWriteBatch
        try:
            yield readable_write_batch
        except Exception:
            cls.logger.exception(
                "Unexpected error in atomic db write, dropped partial writes: %r",
                readable_write_batch._diff(),
            )
            raise
        else:
            readable_write_batch._commit()
        finally:
            # force a shutdown of this batch, to prevent out-of-context usage
            readable_write_batch._track_diff = None
            readable_write_batch._write_target_db = None