blob: 1b469beb1b8345baefd41ae3e6e7cbc3feec200b (
plain) (
blame)
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
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.zookeeper;
import ai.vespa.validation.Validation;
import com.yahoo.cloud.config.ZookeeperServerConfig;
import com.yahoo.component.AbstractComponent;
import com.yahoo.component.annotation.Inject;
import java.nio.file.Path;
import java.time.Duration;
/**
* Starts or reconfigures zookeeper cluster.
* The QuorumPeer conditionally created here is owned by the Reconfigurer;
* when it already has a peer, that peer is used here in case start or shutdown is required.
* Guarantees that server is up by writing a node to ZooKeeper successfully before
* returning from constructor.
*
* @author hmusum
*/
public class ReconfigurableVespaZooKeeperServer extends AbstractComponent implements VespaZooKeeperServer {
private QuorumPeer peer;
@Inject
public ReconfigurableVespaZooKeeperServer(Reconfigurer reconfigurer, ZookeeperServerConfig zookeeperServerConfig) {
Validation.require(zookeeperServerConfig.dynamicReconfiguration(),
zookeeperServerConfig.dynamicReconfiguration(),
"dynamicReconfiguration must be true");
peer = reconfigurer.startOrReconfigure(zookeeperServerConfig, this, () -> peer = new VespaQuorumPeer());
}
@Override
public void shutdown() {
peer.shutdown(Duration.ofMinutes(1));
}
@Override
public void start(Path configFilePath) {
peer.start(configFilePath);
}
@Override
public boolean reconfigurable() {
return true;
}
}
|