]> source.dussan.org Git - jgit.git/commitdiff
DHT: Support removing a repository name 92/3592/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 27 May 2011 00:25:59 +0000 (17:25 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 31 May 2011 15:58:45 +0000 (08:58 -0700)
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>
org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/RepositoryIndexTable.java
org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/cache/CacheRepositoryIndexTable.java
org.eclipse.jgit.storage.dht/src/org/eclipse/jgit/storage/dht/spi/memory/MemRepositoryIndexTable.java

index 794db6e5e268c3f766032b0c5f1e1aaa3005b63a..36afd13229abd20d64068d441d7baeb934bc3dc2 100644 (file)
@@ -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;
 }
index 5ff43910f3c2dcafe848e6203a2913fd87846587..b50092c6d1299c319898139695dbc622835eff27 100644 (file)
@@ -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();
+               }
+       }
 }
index 46a1fd619ac5ac2b04cb6a0235f7f2920be5e2ab..000ff77327b75d039e71c580c15cbe33c6defb8a 100644 (file)
@@ -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()));
+       }
 }