Przeglądaj źródła

Support per-BatchRefUpdate atomic transactions

Repurpose RefDatabase#performsAtomicTransactions() slightly, to
indicate that the backend _supports_ atomic transactions, rather than
the current definition, which is that the backend always _uses_ atomic
transactions regardless of whether or not the caller actually wants
them. Allow BatchRefUpdate callers to turn off atomic transactions by
calling setAtomic(false). Defaulting to true means this is backwards
compatible.

Change-Id: I6df78d7df65ab147b4cce7764bd3101db985491c
tags/v4.4.0.201605041135-m1
Dave Borowitz 8 lat temu
rodzic
commit
a37d85ccd6

+ 1
- 0
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties Wyświetl plik

atLeastOnePatternIsRequired=At least one pattern is required. atLeastOnePatternIsRequired=At least one pattern is required.
atLeastTwoFiltersNeeded=At least two filters needed. atLeastTwoFiltersNeeded=At least two filters needed.
atomicPushNotSupported=Atomic push not supported. atomicPushNotSupported=Atomic push not supported.
atomicRefUpdatesNotSupported=Atomic ref updates not supported
authenticationNotSupported=authentication not supported authenticationNotSupported=authentication not supported
badBase64InputCharacterAt=Bad Base64 input character at {0} : {1} (decimal) badBase64InputCharacterAt=Bad Base64 input character at {0} : {1} (decimal)
badEntryDelimiter=Bad entry delimiter badEntryDelimiter=Bad entry delimiter

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java Wyświetl plik

/***/ public String atLeastOnePatternIsRequired; /***/ public String atLeastOnePatternIsRequired;
/***/ public String atLeastTwoFiltersNeeded; /***/ public String atLeastTwoFiltersNeeded;
/***/ public String atomicPushNotSupported; /***/ public String atomicPushNotSupported;
/***/ public String atomicRefUpdatesNotSupported;
/***/ public String authenticationNotSupported; /***/ public String authenticationNotSupported;
/***/ public String badBase64InputCharacterAt; /***/ public String badBase64InputCharacterAt;
/***/ public String badEntryDelimiter; /***/ public String badEntryDelimiter;

+ 1
- 1
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java Wyświetl plik

@Override @Override
public void execute(RevWalk walk, ProgressMonitor monitor) public void execute(RevWalk walk, ProgressMonitor monitor)
throws IOException { throws IOException {
if (performsAtomicTransactions()) {
if (performsAtomicTransactions() && isAtomic()) {
try { try {
lock.writeLock().lock(); lock.writeLock().lock();
batch(getCommands()); batch(getCommands());

+ 6
- 2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/reftree/RefTreeBatch.java Wyświetl plik

} }
if (c.getType() == UPDATE_NONFASTFORWARD) { if (c.getType() == UPDATE_NONFASTFORWARD) {
c.setResult(REJECTED_NONFASTFORWARD); c.setResult(REJECTED_NONFASTFORWARD);
ReceiveCommand.abort(getCommands());
return;
if (isAtomic()) {
ReceiveCommand.abort(getCommands());
return;
} else {
continue;
}
} }
} }
todo.add(new Command(rw, c)); todo.add(new Command(rw, c));

+ 49
- 0
org.eclipse.jgit/src/org/eclipse/jgit/lib/BatchRefUpdate.java Wyświetl plik

/** Push certificate associated with this update. */ /** Push certificate associated with this update. */
private PushCertificate pushCert; private PushCertificate pushCert;


/** Whether updates should be atomic. */
private boolean atomic;

/** /**
* Initialize a new batch update. * Initialize a new batch update.
* *
protected BatchRefUpdate(RefDatabase refdb) { protected BatchRefUpdate(RefDatabase refdb) {
this.refdb = refdb; this.refdb = refdb;
this.commands = new ArrayList<ReceiveCommand>(); this.commands = new ArrayList<ReceiveCommand>();
this.atomic = refdb.performsAtomicTransactions();
} }


/** /**
return refLogMessage == null; return refLogMessage == null;
} }


/**
* Request that all updates in this batch be performed atomically.
* <p>
* When atomic updates are used, either all commands apply successfully, or
* none do. Commands that might have otherwise succeeded are rejected with
* {@code REJECTED_OTHER_REASON}.
* <p>
* This method only works if the underlying ref database supports atomic
* transactions, i.e. {@link RefDatabase#performsAtomicTransactions()} returns
* true. Calling this method with true if the underlying ref database does not
* support atomic transactions will cause all commands to fail with {@code
* REJECTED_OTHER_REASON}.
*
* @param atomic whether updates should be atomic.
* @return {@code this}
* @since 4.4
*/
public BatchRefUpdate setAtomic(boolean atomic) {
this.atomic = atomic;
return this;
}

/**
* @return atomic whether updates should be atomic.
* @since 4.4
*/
public boolean isAtomic() {
return atomic;
}

/** /**
* Set a push certificate associated with this update. * Set a push certificate associated with this update.
* <p> * <p>
* <p> * <p>
* The default implementation of this method performs a sequential reference * The default implementation of this method performs a sequential reference
* update over each reference. * update over each reference.
* <p>
* Implementations must respect the atomicity requirements of the underlying
* database as described in {@link #setAtomic(boolean)} and {@link
* RefDatabase#performsAtomicTransactions()}.
* *
* @param walk * @param walk
* a RevWalk to parse tags in case the storage system wants to * a RevWalk to parse tags in case the storage system wants to
*/ */
public void execute(RevWalk walk, ProgressMonitor monitor) public void execute(RevWalk walk, ProgressMonitor monitor)
throws IOException { throws IOException {

if (atomic && !refdb.performsAtomicTransactions()) {
for (ReceiveCommand c : commands) {
if (c.getResult() == NOT_ATTEMPTED) {
c.setResult(REJECTED_OTHER_REASON,
JGitText.get().atomicRefUpdatesNotSupported);
}
}
return;
}

monitor.beginTask(JGitText.get().updatingReferences, commands.size()); monitor.beginTask(JGitText.get().updatingReferences, commands.size());
List<ReceiveCommand> commands2 = new ArrayList<ReceiveCommand>( List<ReceiveCommand> commands2 = new ArrayList<ReceiveCommand>(
commands.size()); commands.size());

+ 19
- 2
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefDatabase.java Wyświetl plik

} }


/** /**
* @return if the database performs {@code newBatchUpdate()} as an atomic
* transaction.
* Whether the database is capable of performing batch updates as atomic
* transactions.
* <p>
* If true, by default {@link BatchRefUpdate} instances will perform updates
* atomically, meaning either all updates will succeed, or all updates will
* fail. It is still possible to turn off this behavior on a per-batch basis
* by calling {@code update.setAtomic(false)}.
* <p>
* If false, {@link BatchRefUpdate} instances will never perform updates
* atomically, and calling {@code update.setAtomic(true)} will cause the
* entire batch to fail with {@code REJECTED_OTHER_REASON}.
* <p>
* This definition of atomicity is stronger than what is provided by
* {@link org.eclipse.jgit.transport.ReceivePack}. {@code ReceivePack} will
* attempt to reject all commands if it knows in advance some commands may
* fail, even if the storage layer does not support atomic transactions. Here,
* atomicity applies even in the case of unforeseeable errors.
*
* @return whether transactions are atomic by default.
* @since 3.6 * @since 3.6
*/ */
public boolean performsAtomicTransactions() { public boolean performsAtomicTransactions() {

Ładowanie…
Anuluj
Zapisz