Search in sources :

Example 1 with MigrationShard

use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.

the class MigrationPartialSuccessRollBackState method doAction.

@Override
public void doAction() {
    CountDownLatch latch = new CountDownLatch(getHolder().getMigrationShards().size());
    StringBuilder errorMessage = new StringBuilder();
    for (MigrationShard migrationShard : getHolder().getMigrationShards()) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                try {
                    migrationShard.doRollBack();
                } catch (Exception e) {
                    logger.error("[run]" + migrationShard, e);
                    errorMessage.append(LogUtils.error(String.format("%s", migrationShard, e.toString())));
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    try {
        latch.await(migrationWaitTimeMilli, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.error("[MigrationRollBackStat][await][shard][doRollBack][fail]", e);
        errorMessage.append(LogUtils.error(String.format("[wait time exceed]%s ms", migrationWaitTimeMilli)));
    }
    String error = errorMessage.toString();
    if (StringUtil.isEmpty(error)) {
        updateAndProcess(nextAfterSuccess());
    } else {
        updateAndStop(nextAfterFail());
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with MigrationShard

use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.

the class MigrationPartialSuccessState method doAction.

@Override
public void doAction() {
    for (final MigrationShard shard : getHolder().getMigrationShards()) {
        ShardMigrationResult shardMigrationResult = shard.getShardMigrationResult();
        if (!shardMigrationResult.stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
            shardMigrationResult.stepRetry(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC);
            String clusterName = getHolder().clusterName();
            String shardName = shard.shardName();
            logger.info("[doAction][execute]{}, {}", clusterName, shardName);
            executors.execute(new AbstractExceptionLogTask() {

                @Override
                public void doRun() {
                    logger.info("[doMigrate][start]{},{}", clusterName, shardName);
                    shard.doMigrate();
                    logger.info("[doMigrate][done]{},{}", clusterName, shardName);
                }
            });
        }
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) ShardMigrationResult(com.ctrip.xpipe.redis.console.migration.model.ShardMigrationResult)

Example 3 with MigrationShard

use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.

the class AbstractMigrationMigratingState method refresh.

@Override
public void refresh() {
    int setUpNewSuccessCnt = 0;
    int currentlyWorkingCnt = 0;
    List<MigrationShard> migrationShards = getHolder().getMigrationShards();
    final int migrationShardsSize = migrationShards.size();
    for (MigrationShard migrationShard : migrationShards) {
        if (migrationShard.getShardMigrationResult().stepTerminated(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
            if (migrationShard.getShardMigrationResult().stepSuccess(ShardMigrationStep.MIGRATE_NEW_PRIMARY_DC)) {
                ++setUpNewSuccessCnt;
            }
        } else {
            ++currentlyWorkingCnt;
        }
    }
    if (currentlyWorkingCnt == 0) {
        if (setUpNewSuccessCnt == migrationShardsSize) {
            // all success
            int finishedCnt = 0;
            for (MigrationShard migrationShard : migrationShards) {
                if (migrationShard.getShardMigrationResult().stepTerminated(ShardMigrationStep.MIGRATE)) {
                    ++finishedCnt;
                }
            }
            if (0 == finishedCnt && doOtherDcMigrate.compareAndSet(false, true)) {
                doMigrateOtherDc();
            } else if (finishedCnt == migrationShardsSize) {
                logger.info("[success][continue]{}", getHolder().clusterName());
                updateAndProcess(nextAfterSuccess());
            }
        } else {
            // any fail
            logger.info("[fail]{}", getHolder().clusterName());
            if (this instanceof MigrationMigratingState) {
                updateAndProcess(nextAfterFail());
                return;
            }
            if (this instanceof MigrationPartialSuccessState) {
                updateAndStop(nextAfterFail());
                return;
            }
        }
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard)

Example 4 with MigrationShard

use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.

the class AbstractMigrationMigratingState method doMigrateOtherDc.

protected void doMigrateOtherDc() {
    logger.debug("[doMigrateOtherDc]{}", this);
    MigrationCluster migrationCluster = getHolder();
    String clusterName = migrationCluster.clusterName();
    for (MigrationShard migrationShard : migrationCluster.getMigrationShards()) {
        executors.execute(new AbstractExceptionLogTask() {

            @Override
            public void doRun() {
                String shardName = migrationShard.shardName();
                logger.info("[doOtherDcMigrate][start]{},{}", clusterName, shardName);
                migrationShard.doMigrateOtherDc();
                logger.info("[doOtherDcMigrate][done]{},{}", clusterName, shardName);
            }
        });
    }
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) MigrationCluster(com.ctrip.xpipe.redis.console.migration.model.MigrationCluster) AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)

Example 5 with MigrationShard

use of com.ctrip.xpipe.redis.console.migration.model.MigrationShard in project x-pipe by ctripcorp.

the class AbstractMigrationPublishState method getNewMasters.

public List<InetSocketAddress> getNewMasters() {
    List<InetSocketAddress> result = new LinkedList<>();
    for (MigrationShard migrationShard : getHolder().getMigrationShards()) {
        HostPort newMasterAddress = migrationShard.getNewMasterAddress();
        if (newMasterAddress == null) {
            // may force publish
            logger.warn("[getNewMasters][null master]{}", migrationShard.shardName());
            continue;
        }
        result.add(InetSocketAddress.createUnresolved(newMasterAddress.getHost(), newMasterAddress.getPort()));
    }
    return result;
}
Also used : MigrationShard(com.ctrip.xpipe.redis.console.migration.model.MigrationShard) InetSocketAddress(java.net.InetSocketAddress) HostPort(com.ctrip.xpipe.endpoint.HostPort) LinkedList(java.util.LinkedList)

Aggregations

MigrationShard (com.ctrip.xpipe.redis.console.migration.model.MigrationShard)7 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)5 CountDownLatch (java.util.concurrent.CountDownLatch)2 HostPort (com.ctrip.xpipe.endpoint.HostPort)1 MigrationCluster (com.ctrip.xpipe.redis.console.migration.model.MigrationCluster)1 ShardMigrationResult (com.ctrip.xpipe.redis.console.migration.model.ShardMigrationResult)1 InetSocketAddress (java.net.InetSocketAddress)1 LinkedList (java.util.LinkedList)1