Repository navigation
Expand file tree
/
Copy pathObjectStoreConfig.java
More file actions
227 lines (202 loc) · 8.54 KB
/
Copy pathObjectStoreConfig.java
File metadata and controls
227 lines (202 loc) · 8.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/**
*
* Copyright (C) TidesDB
*
* Original Author: Alex Gaetano Padula
*
* Licensed under the Mozilla Public License, v. 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
*
* https://www.mozilla.org/en-US/MPL/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 com.tidesdb;
/**
* Configuration for object store mode behavior.
*/
public class ObjectStoreConfig {
private String localCachePath;
private long localCacheMaxBytes;
private boolean cacheOnRead;
private boolean cacheOnWrite;
private int maxConcurrentUploads;
private int maxConcurrentDownloads;
private long multipartThreshold;
private long multipartPartSize;
private boolean syncManifestToObject;
private boolean replicateWal;
private boolean walUploadSync;
private long walSyncThresholdBytes;
private boolean walSyncOnCommit;
private boolean replicaMode;
private long replicaSyncIntervalUs;
private boolean replicaReplayWal;
private ObjectStoreConfig(Builder builder) {
this.localCachePath = builder.localCachePath;
this.localCacheMaxBytes = builder.localCacheMaxBytes;
this.cacheOnRead = builder.cacheOnRead;
this.cacheOnWrite = builder.cacheOnWrite;
this.maxConcurrentUploads = builder.maxConcurrentUploads;
this.maxConcurrentDownloads = builder.maxConcurrentDownloads;
this.multipartThreshold = builder.multipartThreshold;
this.multipartPartSize = builder.multipartPartSize;
this.syncManifestToObject = builder.syncManifestToObject;
this.replicateWal = builder.replicateWal;
this.walUploadSync = builder.walUploadSync;
this.walSyncThresholdBytes = builder.walSyncThresholdBytes;
this.walSyncOnCommit = builder.walSyncOnCommit;
this.replicaMode = builder.replicaMode;
this.replicaSyncIntervalUs = builder.replicaSyncIntervalUs;
this.replicaReplayWal = builder.replicaReplayWal;
}
/**
* Creates a default object store configuration matching tidesdb_objstore_default_config().
*
* @return a new ObjectStoreConfig with default values
*/
public static ObjectStoreConfig defaultConfig() {
return new Builder().build();
}
/**
* Creates a new builder for ObjectStoreConfig.
*
* @return a new Builder
*/
public static Builder builder() {
return new Builder();
}
public String getLocalCachePath() { return localCachePath; }
public long getLocalCacheMaxBytes() { return localCacheMaxBytes; }
public boolean isCacheOnRead() { return cacheOnRead; }
public boolean isCacheOnWrite() { return cacheOnWrite; }
public int getMaxConcurrentUploads() { return maxConcurrentUploads; }
public int getMaxConcurrentDownloads() { return maxConcurrentDownloads; }
public long getMultipartThreshold() { return multipartThreshold; }
public long getMultipartPartSize() { return multipartPartSize; }
public boolean isSyncManifestToObject() { return syncManifestToObject; }
public boolean isReplicateWal() { return replicateWal; }
public boolean isWalUploadSync() { return walUploadSync; }
public long getWalSyncThresholdBytes() { return walSyncThresholdBytes; }
public boolean isWalSyncOnCommit() { return walSyncOnCommit; }
public boolean isReplicaMode() { return replicaMode; }
public long getReplicaSyncIntervalUs() { return replicaSyncIntervalUs; }
public boolean isReplicaReplayWal() { return replicaReplayWal; }
/**
* Builder for ObjectStoreConfig.
*/
public static class Builder {
private String localCachePath = null;
private long localCacheMaxBytes = 0;
private boolean cacheOnRead = true;
private boolean cacheOnWrite = true;
private int maxConcurrentUploads = 4;
private int maxConcurrentDownloads = 8;
private long multipartThreshold = 64 * 1024 * 1024;
private long multipartPartSize = 8 * 1024 * 1024;
private boolean syncManifestToObject = true;
private boolean replicateWal = true;
private boolean walUploadSync = false;
private long walSyncThresholdBytes = 1048576;
private boolean walSyncOnCommit = false;
private boolean replicaMode = false;
private long replicaSyncIntervalUs = 5000000;
private boolean replicaReplayWal = true;
public Builder localCachePath(String localCachePath) {
this.localCachePath = localCachePath;
return this;
}
public Builder localCacheMaxBytes(long localCacheMaxBytes) {
this.localCacheMaxBytes = localCacheMaxBytes;
return this;
}
public Builder cacheOnRead(boolean cacheOnRead) {
this.cacheOnRead = cacheOnRead;
return this;
}
public Builder cacheOnWrite(boolean cacheOnWrite) {
this.cacheOnWrite = cacheOnWrite;
return this;
}
public Builder maxConcurrentUploads(int maxConcurrentUploads) {
this.maxConcurrentUploads = maxConcurrentUploads;
return this;
}
public Builder maxConcurrentDownloads(int maxConcurrentDownloads) {
this.maxConcurrentDownloads = maxConcurrentDownloads;
return this;
}
public Builder multipartThreshold(long multipartThreshold) {
this.multipartThreshold = multipartThreshold;
return this;
}
public Builder multipartPartSize(long multipartPartSize) {
this.multipartPartSize = multipartPartSize;
return this;
}
public Builder syncManifestToObject(boolean syncManifestToObject) {
this.syncManifestToObject = syncManifestToObject;
return this;
}
public Builder replicateWal(boolean replicateWal) {
this.replicateWal = replicateWal;
return this;
}
public Builder walUploadSync(boolean walUploadSync) {
this.walUploadSync = walUploadSync;
return this;
}
public Builder walSyncThresholdBytes(long walSyncThresholdBytes) {
this.walSyncThresholdBytes = walSyncThresholdBytes;
return this;
}
public Builder walSyncOnCommit(boolean walSyncOnCommit) {
this.walSyncOnCommit = walSyncOnCommit;
return this;
}
public Builder replicaMode(boolean replicaMode) {
this.replicaMode = replicaMode;
return this;
}
public Builder replicaSyncIntervalUs(long replicaSyncIntervalUs) {
this.replicaSyncIntervalUs = replicaSyncIntervalUs;
return this;
}
public Builder replicaReplayWal(boolean replicaReplayWal) {
this.replicaReplayWal = replicaReplayWal;
return this;
}
public ObjectStoreConfig build() {
validate();
return new ObjectStoreConfig(this);
}
private void validate() {
if (localCacheMaxBytes < 0) {
throw new IllegalArgumentException("localCacheMaxBytes must not be negative, was: " + localCacheMaxBytes);
}
if (maxConcurrentUploads <= 0) {
throw new IllegalArgumentException("maxConcurrentUploads must be positive, was: " + maxConcurrentUploads);
}
if (maxConcurrentDownloads <= 0) {
throw new IllegalArgumentException("maxConcurrentDownloads must be positive, was: " + maxConcurrentDownloads);
}
if (multipartThreshold < 0) {
throw new IllegalArgumentException("multipartThreshold must not be negative, was: " + multipartThreshold);
}
if (multipartPartSize < 0) {
throw new IllegalArgumentException("multipartPartSize must not be negative, was: " + multipartPartSize);
}
if (walSyncThresholdBytes < 0) {
throw new IllegalArgumentException("walSyncThresholdBytes must not be negative, was: " + walSyncThresholdBytes);
}
if (replicaSyncIntervalUs < 0) {
throw new IllegalArgumentException("replicaSyncIntervalUs must not be negative, was: " + replicaSyncIntervalUs);
}
}
}
}