- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.linecorp.centraldogma.server.internal.replication.ZooKeeperCommandExecutor
类的一些代码示例,展示了ZooKeeperCommandExecutor
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperCommandExecutor
类的具体详情如下:
包路径:com.linecorp.centraldogma.server.internal.replication.ZooKeeperCommandExecutor
类名称:ZooKeeperCommandExecutor
暂无
代码示例来源:origin: line/centraldogma
private <T> T blockingExecute(Command<T> command) throws Exception {
createParentNodes();
try (SafeLock ignored = safeLock(command.executionPath())) {
// NB: We are sure no other replicas will append the conflicting logs (the commands with the
// same execution path) while we hold the lock for the command's execution path.
//
// Other replicas may still append the logs with different execution paths, because, by design,
// two commands never conflict with each other if they have different execution paths.
final List<String> recentRevisions = curator.getChildren().forPath(absolutePath(LOG_PATH));
if (!recentRevisions.isEmpty()) {
final long lastRevision = recentRevisions.stream().mapToLong(Long::parseLong).max().getAsLong();
replayLogs(lastRevision);
}
final T result = delegate.execute(command).get();
final ReplicationLog<T> log = new ReplicationLog<>(replicaId(), command, result);
// Store the command execution log to ZooKeeper.
final long revision = storeLog(log);
logger.debug("logging OK. revision = {}, log = {}", revision, log);
return result;
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
@Override
protected <T> CompletableFuture<T> doExecute(int replicaId, Command<T> command) throws Exception {
final CompletableFuture<T> future = new CompletableFuture<>();
executor.execute(() -> {
try {
future.complete(blockingExecute(replicaId, command));
} catch (Throwable t) {
future.completeExceptionally(t);
}
});
return future;
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
private void createParentNodes() throws Exception {
if (createdParentNodes) {
return;
}
// Create the zkPath if it does not exist.
createZkPathIfMissing(absolutePath());
createZkPathIfMissing(absolutePath(LOG_PATH));
createZkPathIfMissing(absolutePath(LOG_BLOCK_PATH));
createZkPathIfMissing(absolutePath(LOCK_PATH));
createdParentNodes = true;
}
代码示例来源:origin: line/centraldogma
@VisibleForTesting
Optional<ReplicationLog<?>> loadLog(long revision, boolean skipIfSameReplica) {
try {
createParentNodes();
final String logPath = absolutePath(LOG_PATH) + '/' + pathFromRevision(revision);
final LogMeta logMeta = Jackson.readValue(curator.getData().forPath(logPath), LogMeta.class);
if (skipIfSameReplica && replicaId() == logMeta.replicaId()) {
return Optional.empty();
}
final byte[] bytes = new byte[logMeta.size()];
int offset = 0;
for (long blockId : logMeta.blocks()) {
final String blockPath = absolutePath(LOG_BLOCK_PATH) + '/' + pathFromRevision(blockId);
final byte[] b = curator.getData().forPath(blockPath);
System.arraycopy(b, 0, bytes, offset, b.length);
offset += b.length;
}
assert logMeta.size() == offset;
final ReplicationLog<?> log = Jackson.readValue(bytes, ReplicationLog.class);
return Optional.of(log);
} catch (Exception e) {
logger.error("Failed to load a log at revision {}; entering read-only mode", revision, e);
stopLater();
throw new ReplicationException("failed to load a log at revision " + revision, e);
}
}
代码示例来源:origin: line/centraldogma
for (;;) {
final long nextRevision = info.lastReplayedRevision + 1;
final Optional<ReplicationLog<?>> log = loadLog(nextRevision, true);
if (log.isPresent()) {
final ReplicationLog<?> l = log.get();
logger.error("Failed to replay a log at revision {}; entering read-only mode",
info.lastReplayedRevision, e);
stopLater();
updateLastReplayedRevision(targetRevision);
} catch (Exception e) {
logger.error("Failed to update {} to {}; entering read-only mode",
revisionFile, targetRevision, e);
stopLater();
throw new ReplicationException("failed to update " + revisionFile + " to " + targetRevision, e);
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
private long storeLog(ReplicationLog<?> log) {
try {
final byte[] bytes = Jackson.writeValueAsBytes(log);
assert bytes.length > 0;
final LogMeta logMeta = new LogMeta(log.replicaId(), System.currentTimeMillis(), bytes.length);
final int count = (bytes.length + MAX_BYTES - 1) / MAX_BYTES;
for (int i = 0; i < count; ++i) {
final int start = i * MAX_BYTES;
final int end = Math.min((i + 1) * MAX_BYTES, bytes.length);
final byte[] b = Arrays.copyOfRange(bytes, start, end);
final String blockPath = curator.create()
.withMode(CreateMode.PERSISTENT_SEQUENTIAL)
.forPath(absolutePath(LOG_BLOCK_PATH) + '/', b);
final long blockId = revisionFromPath(blockPath);
logMeta.appendBlock(blockId);
}
final String logPath =
curator.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL)
.forPath(absolutePath(LOG_PATH) + '/', Jackson.writeValueAsBytes(logMeta));
return revisionFromPath(logPath);
} catch (Exception e) {
logger.error("Failed to store a log; entering read-only mode: {}", log, e);
stopLater();
throw new ReplicationException("failed to store a log: " + log, e);
}
}
代码示例来源:origin: line/centraldogma
lastReplayedRevision = getLastReplayedRevision();
listenerInfo = new ListenerInfo(lastReplayedRevision, onTakeLeadership, onReleaseLeadership);
} catch (Exception e) {
quorumPeer = startZooKeeper();
retryPolicy = RETRY_POLICY_ALWAYS;
logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH),
true, false, logWatcherExecutor);
logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
leaderSelectorExecutor = Executors.newSingleThreadExecutor(
new DefaultThreadFactory("zookeeper-leader-selector", true));
leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH),
leaderSelectorExecutor, oldLogRemover);
leaderSelector.start();
代码示例来源:origin: line/centraldogma
private SafeLock safeLock(String executionPath) {
final InterProcessMutex mtx = mutexMap.computeIfAbsent(
executionPath, k -> new InterProcessMutex(curator, absolutePath(LOCK_PATH, executionPath)));
try {
mtx.acquire();
} catch (Exception e) {
logger.error("Failed to acquire a lock for {}; entering read-only mode", executionPath, e);
stopLater();
throw new ReplicationException("failed to acquire a lock for " + executionPath, e);
}
return () -> {
try {
mtx.release();
} catch (Exception ignored) {
// Ignore.
}
};
}
代码示例来源:origin: line/centraldogma
copyZkProperty(zkProps, "initLimit", "5");
copyZkProperty(zkProps, "syncLimit", "10");
copyZkProperty(zkProps, "tickTime", "3000");
copyZkProperty(zkProps, "syncEnabled", "true");
copyZkProperty(zkProps, "autopurge.snapRetainCount", "3");
copyZkProperty(zkProps, "autopurge.purgeInterval", "1");
if (isStopping()) {
throw new InterruptedException("Stop requested before joining the cluster");
代码示例来源:origin: line/centraldogma
final Replica replica3 = cluster.get(2);
final Replica replica4 = cluster.get(3);
replica4.rm.stop().join();
replica1.rm.execute(command1).join();
final Optional<ReplicationLog<?>> commandResult2 = replica1.rm.loadLog(0, false);
assertThat(commandResult2.get().command()).isEqualTo(command1);
assertThat(commandResult2.get().result()).isNull();
replica3.rm.stop().join();
replica1.rm.execute(command2).join();
await().untilAsserted(() -> verify(replica1.delegate).apply(eq(command2)));
await().untilAsserted(() -> verify(replica2.delegate).apply(eq(command2)));
replica3.rm.start().join();
verifyTwoIndependentCommands(replica3, command1, command2);
replica4.rm.start().join();
verifyTwoIndependentCommands(replica4, command1, command2);
} finally {
for (Replica r : cluster) {
r.rm.stop();
代码示例来源:origin: line/centraldogma
for (int j = 0; j < COMMANDS_PER_REPLICA; j++) {
try {
r.rm.execute(command).join();
} catch (Exception e) {
throw new Error(e);
@SuppressWarnings("unchecked")
final ReplicationLog<Revision> log =
(ReplicationLog<Revision>) r.rm.loadLog(i, false).get();
replicas.forEach(r -> r.rm.stop());
代码示例来源:origin: line/centraldogma
Replica(InstanceSpec spec, Map<Integer, ZooKeeperAddress> servers,
Function<Command<?>, CompletableFuture<?>> delegate, boolean start) throws Exception {
this.delegate = delegate;
dataDir = spec.getDataDirectory();
final int id = spec.getServerId();
final ZooKeeperReplicationConfig zkCfg = new ZooKeeperReplicationConfig(id, servers);
rm = new ZooKeeperCommandExecutor(zkCfg, dataDir, new AbstractCommandExecutor(null, null) {
@Override
public int replicaId() {
return id;
}
@Override
protected void doStart(@Nullable Runnable onTakeLeadership,
@Nullable Runnable onReleaseLeadership) {}
@Override
protected void doStop(@Nullable Runnable onReleaseLeadership) {}
@Override
@SuppressWarnings("unchecked")
protected <T> CompletableFuture<T> doExecute(Command<T> command) {
return (CompletableFuture<T>) delegate.apply(command);
}
}, null, null);
startFuture = start ? rm.start() : null;
}
代码示例来源:origin: line/centraldogma
private CommandExecutor newZooKeeperCommandExecutor(ProjectManager pm, Executor repositoryWorker,
@Nullable SessionManager sessionManager,
@Nullable Consumer<CommandExecutor> onTakeLeadership,
@Nullable Runnable onReleaseLeadership) {
final ZooKeeperReplicationConfig zkCfg = (ZooKeeperReplicationConfig) cfg.replicationConfig();
// Delete the old UUID replica ID which is not used anymore.
new File(cfg.dataDir(), "replica_id").delete();
// TODO(trustin): Provide a way to restart/reload the replicator
// so that we can recover from ZooKeeper maintenance automatically.
return new ZooKeeperCommandExecutor(zkCfg, cfg.dataDir(),
new StandaloneCommandExecutor(pm,
repositoryWorker,
sessionManager,
null, null),
onTakeLeadership, onReleaseLeadership);
}
代码示例来源:origin: line/centraldogma
private static String absolutePath(String... pathElements) {
if (pathElements.length == 0) {
return PATH_PREFIX;
}
return path(PATH_PREFIX, path(pathElements));
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
@VisibleForTesting
Optional<ReplicationLog<?>> loadLog(long revision, boolean skipIfSameReplica) {
try {
createParentNodes();
final String logPath = absolutePath(LOG_PATH) + '/' + pathFromRevision(revision);
final LogMeta logMeta = Jackson.readValue(curator.getData().forPath(logPath), LogMeta.class);
if (skipIfSameReplica && replicaId() == logMeta.replicaId()) {
return Optional.empty();
}
final byte[] bytes = new byte[logMeta.size()];
int offset = 0;
for (long blockId : logMeta.blocks()) {
final String blockPath = absolutePath(LOG_BLOCK_PATH) + '/' + pathFromRevision(blockId);
final byte[] b = curator.getData().forPath(blockPath);
System.arraycopy(b, 0, bytes, offset, b.length);
offset += b.length;
}
assert logMeta.size() == offset;
final ReplicationLog<?> log = Jackson.readValue(bytes, ReplicationLog.class);
return Optional.of(log);
} catch (Exception e) {
logger.error("Failed to load a log at revision {}; entering read-only mode", revision, e);
stopLater();
throw new ReplicationException("failed to load a log at revision " + revision, e);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
for (;;) {
final long nextRevision = info.lastReplayedRevision + 1;
final Optional<ReplicationLog<?>> log = loadLog(nextRevision, true);
if (log.isPresent()) {
final ReplicationLog<?> l = log.get();
logger.error("Failed to replay a log at revision {}; entering read-only mode",
info.lastReplayedRevision, e);
stopLater();
updateLastReplayedRevision(targetRevision);
} catch (Exception e) {
logger.error("Failed to update {} to {}; entering read-only mode",
revisionFile, targetRevision, e);
stopLater();
throw new ReplicationException("failed to update " + revisionFile + " to " + targetRevision, e);
代码示例来源:origin: line/centraldogma
private long storeLog(ReplicationLog<?> log) {
try {
final byte[] bytes = Jackson.writeValueAsBytes(log);
assert bytes.length > 0;
final LogMeta logMeta = new LogMeta(log.replicaId(), System.currentTimeMillis(), bytes.length);
final int count = (bytes.length + MAX_BYTES - 1) / MAX_BYTES;
for (int i = 0; i < count; ++i) {
final int start = i * MAX_BYTES;
final int end = Math.min((i + 1) * MAX_BYTES, bytes.length);
final byte[] b = Arrays.copyOfRange(bytes, start, end);
final String blockPath = curator.create()
.withMode(CreateMode.PERSISTENT_SEQUENTIAL)
.forPath(absolutePath(LOG_BLOCK_PATH) + '/', b);
final long blockId = revisionFromPath(blockPath);
logMeta.appendBlock(blockId);
}
final String logPath =
curator.create().withMode(CreateMode.PERSISTENT_SEQUENTIAL)
.forPath(absolutePath(LOG_PATH) + '/', Jackson.writeValueAsBytes(logMeta));
return revisionFromPath(logPath);
} catch (Exception e) {
logger.error("Failed to store a log; entering read-only mode: {}", log, e);
stopLater();
throw new ReplicationException("failed to store a log: " + log, e);
}
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
lastReplayedRevision = getLastReplayedRevision();
listenerInfo = new ListenerInfo(lastReplayedRevision, onTakeLeadership, onReleaseLeadership);
} catch (Exception e) {
quorumPeer = startZooKeeper();
retryPolicy = RETRY_POLICY_ALWAYS;
logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH),
true, false, logWatcherExecutor);
logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
leaderSelectorExecutor = Executors.newSingleThreadExecutor(
new DefaultThreadFactory("zookeeper-leader-selector", true));
leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH),
leaderSelectorExecutor, oldLogRemover);
leaderSelector.start();
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server
private SafeLock safeLock(String executionPath) {
final InterProcessMutex mtx = mutexMap.computeIfAbsent(
executionPath, k -> new InterProcessMutex(curator, absolutePath(LOCK_PATH, executionPath)));
try {
mtx.acquire();
} catch (Exception e) {
logger.error("Failed to acquire a lock for {}; entering read-only mode", executionPath, e);
stopLater();
throw new ReplicationException("failed to acquire a lock for " + executionPath, e);
}
return () -> {
try {
mtx.release();
} catch (Exception ignored) {
// Ignore.
}
};
}
代码示例来源:origin: com.linecorp.centraldogma/centraldogma-server-shaded
copyZkProperty(zkProps, "initLimit", "5");
copyZkProperty(zkProps, "syncLimit", "10");
copyZkProperty(zkProps, "tickTime", "3000");
copyZkProperty(zkProps, "syncEnabled", "true");
copyZkProperty(zkProps, "autopurge.snapRetainCount", "7");
copyZkProperty(zkProps, "autopurge.purgeInterval", "24");
if (isStopping()) {
throw new InterruptedException("Stop requested before joining the cluster");
LMAX Disruptor 通常使用以下方法实现: 如本例所示,Replicator 负责将输入事件\命令复制到从节点。跨一组节点进行复制需要我们应用共识算法,以防我们希望系统在出现网络故障、主故障
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我对这两个概念感到困惑:In-graph replication和 Between-graph replication阅读 Replicated training 时在 tensorflow 的官方
我在事件监视器中收到以下错误, The row was not found at the Subscriber when applying the replicated command. (Sourc
我正在尝试设置 mysql 复制。我看到了在不同地方使用的两个提到的选项。我觉得replicate-rewrite-db是在master和slave中的数据库名称不同的情况下使用的。这是这两个选项之间
我正在关注 Realm Postgres Connector 引用,用于将我们的 Realm 数据库与我们的 Heroku PostgreSQL 数据库同步:https://docs.realm.io
我很难找到数据同步和复制之间的差异。 据我所知,复制使 2 个数据库之间的所有数据都相同。同步不一定使两个数据库之间的所有数据都相同。复制是一次传输,同步可以是小更新以保持数据一致吗?我不太确定,请在
我们刚刚成功地将一个主服务器备份到了一个热备服务器上。但是,当我们尝试查询热备时,会出现以下错误: ERROR: cannot assign TransactionIds during recover
有两个进程访问共享变量x,y和z。每个进程访问用于保存这些变量的存储的不同副本。 x,y和z的初始值是0。 流程1: x = 1; if (y == 0) z++; 和过程2: y = 1; if
我需要一个图形数据库,该数据库需要备份并可能在较低的抽象级别上访问。为了负载平衡,它也必须分布,(单主复制就可以了)。 我知道可以使用自引用键值存储来实现图形数据库。 Git 对象数据库就是这种模式的
我正在构建一个解决方案,该解决方案将部署在全局多个地区的多个数据中心,每个数据中心都有一个在每个地区主动更新的数据副本。我将在每个数据中心有多个数据库和文件系统的组合,它们的状态必须保持一致(在一个数
我有 2 个数据库 X“生产”和 Y“测试” 数据库 X 的结构应与 Y 相同。但是,他们并不是因为我的疯狂而对制作进行了很多改动。现在,我需要以某种方式导出 X 并将其导入 Y 而不会破坏任何复制。
使用REPLICATE(以指定的次数重复字符表达式)函数 REPLICATE函数用于以指定的次数重复字符表达式。 语法: REPLICATE (character_expression,int
我的理解在这里可能有误。据我了解,Couchbase 使用智能客户端来自动选择要在集群中写入或读取的节点。我不明白的是,当这些数据被写入/读取时,它是否也立即写入所有其他节点?如果是这样,在节点发生故
我目前正在处理 Crystal Reports 中的一个项目,该项目拒绝使用 Oracle 10g 中允许的未记录函数 WM_CONCAT。 这是WM_CONCAT头信息 WM_CONCAT(p1 I
我有一个在防火墙后面运行的 SOLR 实例。我即将建立另一个不会被防火墙保护的实例。但是,SOLR 似乎只支持拉复制而不支持推送复制。 为了保持相同的安全级别,我有哪些选择?我宁愿不要在防火墙中打开太
有人可以解释为 RavenDB 设置复制的基本步骤吗?我正在使用 build 888。根据我在网上找到的内容,我可以猜测可能需要做什么,但我宁愿确定。 我相信这是复制的官方文档: http://rav
我想在SQL Server和MySQL之间设置复制,其中SQL Server是主数据库服务器,而MySQL是从属服务器(在Linux上)。 有没有办法设置这种情况?帮我 。 最佳答案 我的答案可能来不
我想了解以下 Lotus-Domino 服务器到服务器复制场景中会发生什么: 服务器 A 有 A 数据库的副本。 服务器 B 具有相同数据库的副本。 两台服务器都对数据库具有管理员访问权限,包括删除文
我有一个 2 节点的 cassandra 集群,复制因子为 2,AutoBootStrap=true。启动期间一切正常,两个节点都能看到对方。让我们称这些节点为 A 和 B。 通过节点 A 向 cas
我是一名优秀的程序员,十分优秀!