From 50f236aff861ab2a6851eb96cff6fe07b775bb5b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 26 May 2011 17:25:59 -0700 Subject: [PATCH] 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 --- .../storage/dht/spi/RepositoryIndexTable.java | 17 +++++++++++++++++ .../spi/cache/CacheRepositoryIndexTable.java | 14 ++++++++++++++ .../dht/spi/memory/MemRepositoryIndexTable.java | 12 ++++++++++++ 3 files changed, 43 insertions(+) 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 794db6e5e..36afd1322 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. + *

+ * 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 5ff43910f..b50092c6d 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 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 46a1fd619..000ff7732 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())); + } }