diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2011-05-26 17:25:59 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2011-05-31 08:58:45 -0700 |
commit | 50f236aff861ab2a6851eb96cff6fe07b775bb5b (patch) | |
tree | 64a726a4a7ecf9bc738eab49e6ab4490f94aa528 | |
parent | 042a66fe8c2feef7b831b1999b8cd6e9a0181944 (diff) | |
download | jgit-50f236aff861ab2a6851eb96cff6fe07b775bb5b.tar.gz jgit-50f236aff861ab2a6851eb96cff6fe07b775bb5b.zip |
DHT: Support removing a repository name
The first step to deleting a repository from the DHT storage is to
remove the name binding in the RepositoryIndexTable, making the
repository unavailable for lookup.
Change-Id: I469bf92f4bf2f555a15949569b21937c14cb142b
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
3 files changed, 43 insertions, 0 deletions
diff --git a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/RepositoryIndexTable.java b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/RepositoryIndexTable.java index 794db6e5e2..36afd13229 100644 --- a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/RepositoryIndexTable.java +++ b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/RepositoryIndexTable.java @@ -87,4 +87,21 @@ public interface RepositoryIndexTable { */ public void putUnique(RepositoryName name, RepositoryKey key) throws DhtException, TimeoutException; + + /** + * Remove the association of a name to an identifier. + * <p> + * This method must use some sort of transaction system to ensure the name + * is removed only if it currently references {@code key}. This may require + * running some sort of lock management service in parallel to the database. + * + * @param name + * name of the repository. + * @param key + * internal key defining the repository. + * @throws DhtException + * @throws TimeoutException + */ + public void remove(RepositoryName name, RepositoryKey key) + throws DhtException, TimeoutException; } diff --git a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/cache/CacheRepositoryIndexTable.java b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/cache/CacheRepositoryIndexTable.java index 5ff43910f3..b50092c6d1 100644 --- a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/cache/CacheRepositoryIndexTable.java +++ b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/cache/CacheRepositoryIndexTable.java @@ -128,4 +128,18 @@ public class CacheRepositoryIndexTable implements RepositoryIndexTable { throw new TimeoutException(); } } + + public void remove(RepositoryName name, RepositoryKey key) + throws DhtException, TimeoutException { + db.remove(name, key); + + Sync<Void> sync = Sync.create(); + CacheKey memKey = ns.key(name); + client.modify(singleton(Change.remove(memKey)), sync); + try { + sync.get(options.getTimeout()); + } catch (InterruptedException e) { + throw new TimeoutException(); + } + } } diff --git a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/memory/MemRepositoryIndexTable.java b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/memory/MemRepositoryIndexTable.java index 46a1fd619a..000ff77327 100644 --- a/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/memory/MemRepositoryIndexTable.java +++ b/org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/memory/MemRepositoryIndexTable.java @@ -78,4 +78,16 @@ final class MemRepositoryIndexTable implements RepositoryIndexTable { throw new DhtException(MessageFormat.format( DhtText.get().repositoryAlreadyExists, name.asString())); } + + public void remove(RepositoryName name, RepositoryKey key) + throws DhtException, TimeoutException { + boolean ok = table.compareAndSet( + name.asBytes(), + colId.name(), + key.asBytes(), + null); + if (!ok) + throw new DhtException(MessageFormat.format( + DhtText.get().repositoryAlreadyExists, name.asString())); + } } |