This is an automated email from the ASF dual-hosted git repository. lzljs3620320 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink-table-store.git
commit 58d50fb35e37dd4f8482df4fd83de06b3d211791 Author: JingsongLi <lzljs3620...@aliyun.com> AuthorDate: Thu Jan 13 17:38:47 2022 +0800 [FLINK-25630] Introduce MergeTreeOptions --- .../store/file/mergetree/MergeTreeOptions.java | 132 +++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/MergeTreeOptions.java b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/MergeTreeOptions.java new file mode 100644 index 0000000..d6d1ad9 --- /dev/null +++ b/flink-table-store-core/src/main/java/org/apache/flink/table/store/file/mergetree/MergeTreeOptions.java @@ -0,0 +1,132 @@ +/* + * 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.flink.table.store.file.mergetree; + +import org.apache.flink.configuration.ConfigOption; +import org.apache.flink.configuration.ConfigOptions; +import org.apache.flink.configuration.MemorySize; +import org.apache.flink.configuration.ReadableConfig; + +/** Options for merge tree. */ +public class MergeTreeOptions { + + public static final ConfigOption<MemorySize> WRITE_BUFFER_SIZE = + ConfigOptions.key("write-buffer-size") + .memoryType() + .defaultValue(MemorySize.parse("64 mb")) + .withDescription( + "Amount of data to build up in memory before converting to a sorted on-disk file."); + + public static final ConfigOption<MemorySize> PAGE_SIZE = + ConfigOptions.key("page-size") + .memoryType() + .defaultValue(MemorySize.parse("1 mb")) + .withDescription("Memory page size."); + + public static final ConfigOption<MemorySize> TARGET_FILE_SIZE = + ConfigOptions.key("target-file-size") + .memoryType() + .defaultValue(MemorySize.ofMebiBytes(128)) + .withDescription("Target size of a file."); + + public static final ConfigOption<Integer> NUM_SORTED_RUNS_MAX = + ConfigOptions.key("num-sorted-run.max") + .intType() + .defaultValue(5) + .withDescription( + "The max sorted run number. Includes level0 files (one file one sorted run) and " + + "high-level runs (one level one sorted run)."); + + public static final ConfigOption<Integer> NUM_LEVELS = + ConfigOptions.key("num-levels") + .intType() + .defaultValue(4) + .withDescription( + "Total level number, for example, there are 3 levels, including 0,1,2 levels."); + + public static final ConfigOption<Boolean> COMMIT_FORCE_COMPACT = + ConfigOptions.key("commit.force-compact") + .booleanType() + .defaultValue(false) + .withDescription("Whether to force a compaction before commit."); + + public static final ConfigOption<Integer> COMPACTION_MAX_SIZE_AMPLIFICATION_PERCENT = + ConfigOptions.key("compaction.max-size-amplification-percent") + .intType() + .defaultValue(200) + .withDescription( + "The size amplification is defined as the amount (in percentage) of additional storage " + + "needed to store a single byte of data in the merge tree."); + + public static final ConfigOption<Integer> COMPACTION_SIZE_RATIO = + ConfigOptions.key("compaction.size-ratio") + .intType() + .defaultValue(1) + .withDescription( + "Percentage flexibility while comparing sorted run size. If the candidate sorted run(s) " + + "size is 1% smaller than the next sorted run's size, then include next sorted run " + + "into this candidate set."); + + public final long writeBufferSize; + + public final long pageSize; + + public final long targetFileSize; + + public final int numSortedRunMax; + + public final int numLevels; + + public final boolean commitForceCompact; + + public final int maxSizeAmplificationPercent; + + public final int sizeRatio; + + public MergeTreeOptions( + long writeBufferSize, + long pageSize, + long targetFileSize, + int numSortedRunMax, + int numLevels, + boolean commitForceCompact, + int maxSizeAmplificationPercent, + int sizeRatio) { + this.writeBufferSize = writeBufferSize; + this.pageSize = pageSize; + this.targetFileSize = targetFileSize; + this.numSortedRunMax = numSortedRunMax; + this.numLevels = numLevels; + this.commitForceCompact = commitForceCompact; + this.maxSizeAmplificationPercent = maxSizeAmplificationPercent; + this.sizeRatio = sizeRatio; + } + + public MergeTreeOptions(ReadableConfig config) { + this( + config.get(WRITE_BUFFER_SIZE).getBytes(), + config.get(PAGE_SIZE).getBytes(), + config.get(TARGET_FILE_SIZE).getBytes(), + config.get(NUM_SORTED_RUNS_MAX), + config.get(NUM_LEVELS), + config.get(COMMIT_FORCE_COMPACT), + config.get(COMPACTION_MAX_SIZE_AMPLIFICATION_PERCENT), + config.get(COMPACTION_SIZE_RATIO)); + } +}