Skip to content

Commit

Permalink
nfs: remove deviceid to data server mapping when pool is removed
Browse files Browse the repository at this point in the history
Motivation:
When mapping between pool name and IP address is removed, we ween to
remove remove corresponding mapping for device id as well.

Modification:
remove devide id -> data server mapping when pool is removed

Result:
no dangling device ids

Acked-by: Paul Millar
Target: master
Require-book: no
Require-notes: no
  • Loading branch information
kofemann committed Nov 23, 2016
1 parent f70172a commit 3d1371a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Expand Up @@ -107,7 +107,11 @@ Collection<Map.Entry<String,PoolDS>> getEntries() {
PoolDS remove(String pool) {
_wlock.lock();
try {
return _poolNameToIpMap.remove(pool);
PoolDS ds = _poolNameToIpMap.remove(pool);
if (ds != null) {
_deviceMap.remove(ds.getDeviceId());
}
return ds;
} finally {
_wlock.unlock();
}
Expand Down
Expand Up @@ -3,12 +3,12 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.dcache.nfs.v4.xdr.deviceid4;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;

public class PoolDeviceMapTest {

Expand Down Expand Up @@ -43,6 +43,16 @@ public void testUpdateExisting() throws UnknownHostException {
InetSocketAddress[] ip = new InetSocketAddress[]{new InetSocketAddress(0)};

NFSv41Door.PoolDS ds = _poolDeviceMap.getOrCreateDS(name, 0, ip);
Assert.assertSame(ds, _poolDeviceMap.getOrCreateDS(name, 0, ip));
assertSame(ds, _poolDeviceMap.getOrCreateDS(name, 0, ip));
}

@Test
public void testRemoveExisting() throws UnknownHostException {
String name = "somePool";
InetSocketAddress[] ip = new InetSocketAddress[]{new InetSocketAddress(0)};

NFSv41Door.PoolDS ds = _poolDeviceMap.getOrCreateDS(name, 0, ip);
_poolDeviceMap.remove(name);
assertNull("Removed pool stil available", _poolDeviceMap.getByDeviceId(ds.getDeviceId()));
}
}

0 comments on commit 3d1371a

Please sign in to comment.