Skip to content

Commit 79c005c

Browse files
authored
Merge pull request #5367 from gchq/gh-5364_planb_segfault
#5364 Change PlanB snapshots to prevent closure when in use
2 parents 590f782 + dbdccba commit 79c005c

File tree

6 files changed

+1510
-148
lines changed

6 files changed

+1510
-148
lines changed

stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/PlanBConfig.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,85 @@ public int hashCode() {
134134
minTimeToKeepEnvOpen,
135135
snapshotRetryFetchInterval);
136136
}
137+
138+
public static Builder builder() {
139+
return new Builder();
140+
}
141+
142+
public Builder copy() {
143+
return new Builder(this);
144+
}
145+
146+
public static class Builder {
147+
148+
private CacheConfig stateDocCache;
149+
private List<String> nodeList;
150+
private String path;
151+
private StroomDuration minTimeToKeepSnapshots;
152+
private StroomDuration minTimeToKeepEnvOpen;
153+
private StroomDuration snapshotRetryFetchInterval;
154+
155+
public Builder() {
156+
// Set defaults
157+
this.stateDocCache = CacheConfig
158+
.builder()
159+
.maximumSize(1000L)
160+
.expireAfterWrite(StroomDuration.ofMinutes(10))
161+
.build();
162+
this.nodeList = Collections.emptyList();
163+
this.path = "${stroom.home}/planb";
164+
this.minTimeToKeepSnapshots = StroomDuration.ofMinutes(10);
165+
this.minTimeToKeepEnvOpen = StroomDuration.ofMinutes(1);
166+
this.snapshotRetryFetchInterval = StroomDuration.ofMinutes(1);
167+
}
168+
169+
public Builder(final PlanBConfig config) {
170+
this.stateDocCache = config.stateDocCache;
171+
this.nodeList = config.nodeList;
172+
this.path = config.path;
173+
this.minTimeToKeepSnapshots = config.minTimeToKeepSnapshots;
174+
this.minTimeToKeepEnvOpen = config.minTimeToKeepEnvOpen;
175+
this.snapshotRetryFetchInterval = config.snapshotRetryFetchInterval;
176+
}
177+
178+
public Builder stateDocCache(final CacheConfig stateDocCache) {
179+
this.stateDocCache = stateDocCache;
180+
return this;
181+
}
182+
183+
public Builder nodeList(final List<String> nodeList) {
184+
this.nodeList = nodeList;
185+
return this;
186+
}
187+
188+
public Builder path(final String path) {
189+
this.path = path;
190+
return this;
191+
}
192+
193+
public Builder minTimeToKeepSnapshots(final StroomDuration minTimeToKeepSnapshots) {
194+
this.minTimeToKeepSnapshots = minTimeToKeepSnapshots;
195+
return this;
196+
}
197+
198+
public Builder minTimeToKeepEnvOpen(final StroomDuration minTimeToKeepEnvOpen) {
199+
this.minTimeToKeepEnvOpen = minTimeToKeepEnvOpen;
200+
return this;
201+
}
202+
203+
public Builder snapshotRetryFetchInterval(final StroomDuration snapshotRetryFetchInterval) {
204+
this.snapshotRetryFetchInterval = snapshotRetryFetchInterval;
205+
return this;
206+
}
207+
208+
public PlanBConfig build() {
209+
return new PlanBConfig(
210+
stateDocCache,
211+
nodeList,
212+
path,
213+
minTimeToKeepSnapshots,
214+
minTimeToKeepEnvOpen,
215+
snapshotRetryFetchInterval);
216+
}
217+
}
137218
}

stroom-state/stroom-planb-impl/src/main/java/stroom/planb/impl/data/ShardManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import stroom.planb.impl.PlanBConfig;
88
import stroom.planb.impl.PlanBDocCache;
99
import stroom.planb.impl.PlanBDocStore;
10+
import stroom.planb.impl.data.SnapshotShard.DbFactory;
1011
import stroom.planb.impl.db.Db;
12+
import stroom.planb.impl.db.PlanBDb;
1113
import stroom.planb.impl.db.StatePaths;
1214
import stroom.planb.shared.PlanBDoc;
1315
import stroom.task.api.TaskContext;
@@ -41,6 +43,9 @@ public class ShardManager {
4143
public static final String CLEANUP_TASK_NAME = "Plan B Cleanup";
4244
public static final String SNAPSHOT_CREATOR_TASK_NAME = "Plan B Snapshot Creator";
4345

46+
private static final DbFactory DB_FACTORY = (doc, dbDir, byteBuffers, readOnly) ->
47+
PlanBDb.open(doc, dbDir, byteBuffers, true);
48+
4449
private final ByteBuffers byteBuffers;
4550
private final PlanBDocCache planBDocCache;
4651
private final PlanBDocStore planBDocStore;
@@ -256,7 +261,8 @@ private Shard createShard(final PlanBDoc doc) {
256261
configProvider,
257262
statePaths,
258263
fileTransferClient,
259-
doc);
264+
doc,
265+
DB_FACTORY);
260266
}
261267
return new StoreShard(
262268
byteBuffers,

0 commit comments

Comments
 (0)