Github user JamesRTaylor commented on a diff in the pull request: https://github.com/apache/phoenix/pull/129#discussion_r45366823 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java --- @@ -90,44 +108,217 @@ */ public class MutationState implements SQLCloseable { private static final Logger logger = LoggerFactory.getLogger(MutationState.class); - + private static final TransactionCodec CODEC = new TransactionCodec(); + private PhoenixConnection connection; private final long maxSize; - private final ImmutableBytesPtr tempPtr = new ImmutableBytesPtr(); private final Map<TableRef, Map<ImmutableBytesPtr,RowMutationState>> mutations; + private final List<TransactionAware> txAwares; + private final TransactionContext txContext; + private final Set<String> uncommittedPhysicalNames = Sets.newHashSetWithExpectedSize(10); + + private Transaction tx; private long sizeOffset; private int numRows = 0; + private boolean txStarted = false; + private final MutationMetricQueue mutationMetricQueue; private ReadMetricQueue readMetricQueue; - MutationState(long maxSize, PhoenixConnection connection, - Map<TableRef, Map<ImmutableBytesPtr, RowMutationState>> mutations) { - this.maxSize = maxSize; - this.connection = connection; - this.mutations = mutations; - boolean isMetricsEnabled = connection.isRequestLevelMetricsEnabled(); - this.mutationMetricQueue = isMetricsEnabled ? new MutationMetricQueue() - : NoOpMutationMetricsQueue.NO_OP_MUTATION_METRICS_QUEUE; - } - public MutationState(long maxSize, PhoenixConnection connection) { - this(maxSize,connection,0); + this(maxSize,connection, null); + } + + public MutationState(MutationState mutationState) { + this(mutationState.maxSize, mutationState.connection, mutationState.getTransaction()); } public MutationState(long maxSize, PhoenixConnection connection, long sizeOffset) { - this(maxSize, connection, Maps.<TableRef, Map<ImmutableBytesPtr,RowMutationState>>newHashMapWithExpectedSize(connection.getMutateBatchSize())); + this(maxSize, connection, null, sizeOffset); + } + + private MutationState(long maxSize, PhoenixConnection connection, Transaction tx) { + this(maxSize,connection, tx, 0); + } + + private MutationState(long maxSize, PhoenixConnection connection, Transaction tx, long sizeOffset) { + this(maxSize, connection, Maps.<TableRef, Map<ImmutableBytesPtr,RowMutationState>>newHashMapWithExpectedSize(connection.getMutateBatchSize()), tx); this.sizeOffset = sizeOffset; } + MutationState(long maxSize, PhoenixConnection connection, + Map<TableRef, Map<ImmutableBytesPtr, RowMutationState>> mutations, + Transaction tx) { + this.maxSize = maxSize; + this.connection = connection; + this.mutations = mutations; + boolean isMetricsEnabled = connection.isRequestLevelMetricsEnabled(); + this.mutationMetricQueue = isMetricsEnabled ? new MutationMetricQueue() + : NoOpMutationMetricsQueue.NO_OP_MUTATION_METRICS_QUEUE; + this.tx = tx; + if (tx == null) { + this.txAwares = Collections.emptyList(); + TransactionSystemClient txServiceClient = this.connection + .getQueryServices().getTransactionSystemClient(); + this.txContext = new TransactionContext(txServiceClient); + } else { + txAwares = Lists.newArrayList(); + txContext = null; + } + } + public MutationState(TableRef table, Map<ImmutableBytesPtr,RowMutationState> mutations, long sizeOffset, long maxSize, PhoenixConnection connection) { - this(maxSize, connection, sizeOffset); + this(maxSize, connection, null, sizeOffset); this.mutations.put(table, mutations); this.numRows = mutations.size(); + this.tx = connection.getMutationState().getTransaction(); throwIfTooBig(); } + public boolean checkpoint(MutationPlan plan) throws SQLException { --- End diff -- Minor nit: let's rename this to checkpointIfNecessary
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---