Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 : : /*
3 : : * Copyright 2010 Couchbase, Inc
4 : : *
5 : : * Licensed under the Apache License, Version 2.0 (the "License");
6 : : * you may not use this file except in compliance with the License.
7 : : * You may obtain a copy of the License at
8 : : *
9 : : * http://www.apache.org/licenses/LICENSE-2.0
10 : : *
11 : : * Unless required by applicable law or agreed to in writing, software
12 : : * distributed under the License is distributed on an "AS IS" BASIS,
13 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : : * See the License for the specific language governing permissions and
15 : : * limitations under the License.
16 : : */
17 : :
18 : : #include <stdint.h>
19 : : #include <string.h>
20 : : #include <assert.h>
21 : :
22 : : #include "configuration.h"
23 : :
24 : :
25 : 123 : fdb_config get_default_config(void) {
26 : : fdb_config fconfig;
27 : :
28 : 123 : fconfig.chunksize = sizeof(uint64_t);
29 : : // 4KB by default.
30 : 123 : fconfig.blocksize = FDB_BLOCKSIZE;
31 : : // 128MB by default.
32 : 123 : fconfig.buffercache_size = 134217728;
33 : : // 4096 WAL entries by default.
34 : 123 : fconfig.wal_threshold = 4096;
35 : 123 : fconfig.wal_flush_before_commit = true;
36 : 123 : fconfig.auto_commit = false;
37 : : // 0 second by default.
38 : 123 : fconfig.purging_interval = 0;
39 : : // Use a seq btree by default.
40 : 123 : fconfig.seqtree_opt = FDB_SEQTREE_USE;
41 : : // Use a synchronous commit by default.
42 : 123 : fconfig.durability_opt = FDB_DRB_NONE;
43 : 123 : fconfig.flags = FDB_OPEN_FLAG_CREATE;
44 : : // 4MB by default.
45 : 123 : fconfig.compaction_buf_maxsize = FDB_COMP_BUF_MAXSIZE;
46 : : // Clean up cache entries when a file is closed.
47 : 123 : fconfig.cleanup_cache_onclose = true;
48 : : // Compress the body of documents using snappy.
49 : 123 : fconfig.compress_document_body = false;
50 : : // Auto compaction is disabled by default
51 : 123 : fconfig.compaction_mode = FDB_COMPACTION_MANUAL;
52 : : // Compaction threshold, 30% by default
53 : 123 : fconfig.compaction_threshold = FDB_DEFAULT_COMPACTION_THRESHOLD;
54 : 123 : fconfig.compaction_minimum_filesize = 1048576; // 1MB by default
55 : : // 15 seconds by default
56 : 123 : fconfig.compactor_sleep_duration = FDB_COMPACTOR_SLEEP_DURATION;
57 : : // Disable supporting multiple KV instances by default
58 : 123 : fconfig.multi_kv_instances = true;
59 : : // 30 seconds by default
60 : 123 : fconfig.prefetch_duration = 30;
61 : :
62 : 123 : return fconfig;
63 : : }
64 : :
65 : 439 : fdb_kvs_config get_default_kvs_config(void) {
66 : : fdb_kvs_config kvs_config;
67 : :
68 : : // create an empty KV store if it doesn't exist.
69 : 439 : kvs_config.create_if_missing = true;
70 : : // lexicographical key order by default
71 : 439 : kvs_config.custom_cmp = NULL;
72 : :
73 : 439 : return kvs_config;
74 : : }
75 : :
76 : 561 : bool validate_fdb_config(fdb_config *fconfig) {
77 [ - + ]: 561 : assert(fconfig);
78 : :
79 [ + - ][ - + ]: 561 : if (fconfig->chunksize < 4 || fconfig->chunksize > 64) {
80 : : // Chunk size should be set between 4 and 64 bytes.
81 : 0 : return false;
82 : : }
83 [ + - ][ - + ]: 561 : if (fconfig->blocksize < 1024 || fconfig->blocksize > 131072) {
84 : : // Block size should be set between 1KB and 128KB
85 : 0 : return false;
86 : : }
87 [ + + ][ - + ]: 561 : if (fconfig->seqtree_opt != FDB_SEQTREE_NOT_USE &&
88 : : fconfig->seqtree_opt != FDB_SEQTREE_USE) {
89 : 0 : return false;
90 : : }
91 [ + + ][ + - ]: 561 : if (fconfig->durability_opt != FDB_DRB_NONE &&
[ - + ][ # # ]
92 : : fconfig->durability_opt != FDB_DRB_ODIRECT &&
93 : : fconfig->durability_opt != FDB_DRB_ASYNC &&
94 : : fconfig->durability_opt != FDB_DRB_ODIRECT_ASYNC) {
95 : 0 : return false;
96 : : }
97 [ + + ][ + + ]: 561 : if ((fconfig->flags & FDB_OPEN_FLAG_CREATE) &&
98 : : (fconfig->flags & FDB_OPEN_FLAG_RDONLY)) {
99 : 1 : return false;
100 : : }
101 [ - + ]: 560 : if (fconfig->compaction_threshold > 100) {
102 : : // Compaction threshold should be equal or less then 100 (%).
103 : 0 : return false;
104 : : }
105 [ - + ]: 560 : if (fconfig->compactor_sleep_duration == 0) {
106 : : // Sleep duration should be larger than zero
107 : 0 : return false;
108 : : }
109 : :
110 : 561 : return true;
111 : : }
112 : :
113 : 394 : bool validate_fdb_kvs_config(fdb_kvs_config *kvs_config) {
114 : 394 : return true;
115 : : }
116 : :
|