public final StoreResults doOperation()

in elastic-db-tools/src/main/java/com/microsoft/azure/elasticdb/shard/storeops/base/StoreOperation.java [213:290]


    public final StoreResults doOperation() {
        StoreResults result;

        try {
            do {
                result = this.shardMapManager.getRetryPolicy().executeAction(() -> {
                    StoreResults r;

                    try {
                        // Open connections & acquire the necessary app locks.
                        this.establishConnnections(false);

                        // Execute & commit the Global pre-Local operations.
                        r = this.doGlobalPreLocal();

                        // If pending operation, we need to release the locks.
                        if (r.getStoreOperations().isEmpty()) {
                            // Execute & commit the Local operations on source.
                            this.doLocalSource();

                            // Execute & commit the Local operations on target.
                            this.doLocalTarget();

                            // Execute & commit the Global post-Local operations.
                            r = this.doGlobalPostLocal();

                            assert r != null;

                            operationState = StoreOperationState.DoEnd;
                        }
                    }
                    finally {
                        // Figure out the maximum of the progress made yet during Do operation.
                        if (maxDoState.getValue() < operationState.getValue()) {
                            maxDoState = operationState;
                        }

                        // close connections & release the necessary app locks.
                        this.teardownConnections();
                    }

                    return r;
                });

                // If pending operation, deserialize the pending operation and perform Undo.
                if (!result.getStoreOperations().isEmpty()) {
                    assert result.getStoreOperations().size() == 1;

                    try (IStoreOperation op = this.shardMapManager.getStoreOperationFactory().fromLogEntry(this.shardMapManager,
                            result.getStoreOperations().get(0))) {
                        op.undoOperation();
                    }
                    catch (Exception e) {
                        e.printStackTrace();
                        throw new StoreException(e.getMessage(), e.getCause() != null ? (Exception) e.getCause() : e);
                    }
                }
            }
            while (!result.getStoreOperations().isEmpty());
        }
        catch (StoreException se) {
            // If store exception was thrown, we will attempt to undo the current operation.
            this.attemptUndo();

            throw this.onStoreException(se, operationState);
        }
        catch (ShardManagementException e) {
            // If shard map manager exception was thrown, we will attempt to undo the operation.
            this.attemptUndo();

            throw e;
        }
        catch (Exception e) {
            throw new StoreException(e.getMessage(), e);
        }

        return result;
    }