|
26 | 26 | import static org.dcache.util.ByteUnit.EiB; |
27 | 27 | import static org.dcache.util.SqlHelper.tryToClose; |
28 | 28 |
|
| 29 | +import com.github.benmanes.caffeine.cache.AsyncLoadingCache; |
| 30 | +import com.github.benmanes.caffeine.cache.Cache; |
| 31 | +import com.github.benmanes.caffeine.cache.CacheLoader; |
| 32 | +import com.github.benmanes.caffeine.cache.Caffeine; |
29 | 33 | import com.google.common.base.Throwables; |
30 | | -import com.google.common.cache.Cache; |
31 | | -import com.google.common.cache.CacheBuilder; |
32 | | -import com.google.common.cache.CacheLoader; |
33 | | -import com.google.common.cache.LoadingCache; |
34 | 34 | import com.google.common.io.ByteSource; |
35 | 35 | import com.google.common.util.concurrent.ThreadFactoryBuilder; |
36 | 36 | import diskCacheV111.util.RetentionPolicy; |
|
45 | 45 | import java.util.List; |
46 | 46 | import java.util.Map; |
47 | 47 | import java.util.Set; |
48 | | -import java.util.concurrent.ExecutionException; |
| 48 | +import java.util.concurrent.CompletableFuture; |
| 49 | +import java.util.concurrent.CompletionException; |
49 | 50 | import java.util.concurrent.Executor; |
50 | 51 | import java.util.concurrent.Executors; |
51 | 52 | import java.util.concurrent.ScheduledExecutorService; |
@@ -127,30 +128,23 @@ public class JdbcFs implements FileSystemProvider, LeaderLatchListener { |
127 | 128 | .build() |
128 | 129 | ); |
129 | 130 |
|
130 | | - private final LoadingCache<Object, FsStat> _fsStatCache |
131 | | - = CacheBuilder.newBuilder() |
| 131 | + private final AsyncLoadingCache<Object, FsStat> _fsStatCache |
| 132 | + = Caffeine.newBuilder() |
132 | 133 | .refreshAfterWrite(100, TimeUnit.MILLISECONDS) |
133 | | - .build( |
134 | | - CacheLoader.asyncReloading(new CacheLoader<Object, FsStat>() { |
135 | | - |
136 | | - @Override |
137 | | - public FsStat load(Object k) throws Exception { |
138 | | - return JdbcFs.this.getFsStat0(); |
139 | | - } |
140 | | - } |
141 | | - , _fsStatUpdateExecutor)); |
| 134 | + .executor(_fsStatUpdateExecutor) |
| 135 | + .buildAsync(key -> JdbcFs.this.getFsStat0()); |
142 | 136 |
|
143 | 137 | /* The PNFS ID to inode number mapping will never change while dCache is running. |
144 | 138 | */ |
145 | 139 | protected final Cache<String, Long> _inoCache = |
146 | | - CacheBuilder.newBuilder() |
| 140 | + Caffeine.newBuilder() |
147 | 141 | .maximumSize(100000) |
148 | 142 | .build(); |
149 | 143 |
|
150 | 144 | /* The inode number to PNFS ID mapping will never change while dCache is running. |
151 | 145 | */ |
152 | 146 | protected final Cache<Long, String> _idCache = |
153 | | - CacheBuilder.newBuilder() |
| 147 | + Caffeine.newBuilder() |
154 | 148 | .maximumSize(100000) |
155 | 149 | .build(); |
156 | 150 |
|
@@ -725,36 +719,40 @@ public FsInode path2inode(String path, FsInode startFrom) throws ChimeraFsExcept |
725 | 719 | @Override |
726 | 720 | public String inode2id(FsInode inode) throws ChimeraFsException { |
727 | 721 | try { |
728 | | - return _idCache.get(inode.ino(), () -> { |
| 722 | + return _idCache.get(inode.ino(), (key) -> { |
729 | 723 | String id = _sqlDriver.getId(inode); |
730 | 724 | if (id == null) { |
731 | | - throw FileNotFoundChimeraFsException.of(inode); |
| 725 | + throw new RuntimeException(FileNotFoundChimeraFsException.of(inode)); |
732 | 726 | } |
733 | 727 | return id; |
734 | 728 | }); |
735 | | - } catch (ExecutionException e) { |
736 | | - Throwables.throwIfInstanceOf(e.getCause(), ChimeraFsException.class); |
737 | | - Throwables.throwIfInstanceOf(e.getCause(), DataAccessException.class); |
738 | | - Throwables.throwIfUnchecked(e.getCause()); |
739 | | - throw new RuntimeException(e.getCause()); |
| 729 | + } catch (RuntimeException e) { |
| 730 | + if (e.getCause() != null) { |
| 731 | + Throwables.throwIfInstanceOf(e.getCause(), ChimeraFsException.class); |
| 732 | + Throwables.throwIfInstanceOf(e.getCause(), DataAccessException.class); |
| 733 | + Throwables.throwIfUnchecked(e.getCause()); |
| 734 | + } |
| 735 | + throw e; |
740 | 736 | } |
741 | 737 | } |
742 | 738 |
|
743 | 739 | @Override |
744 | 740 | public FsInode id2inode(String id, StatCacheOption option) throws ChimeraFsException { |
745 | 741 | if (option == NO_STAT) { |
746 | 742 | try { |
747 | | - return new FsInode(this, _inoCache.get(id, () -> { |
| 743 | + return new FsInode(this, _inoCache.get(id, (key) -> { |
748 | 744 | Long ino = _sqlDriver.getInumber(id); |
749 | 745 | if (ino == null) { |
750 | | - throw FileNotFoundChimeraFsException.ofPnfsId(id); |
| 746 | + throw new RuntimeException(FileNotFoundChimeraFsException.ofPnfsId(id)); |
751 | 747 | } |
752 | 748 | return ino; |
753 | 749 | })); |
754 | | - } catch (ExecutionException e) { |
755 | | - Throwables.throwIfInstanceOf(e.getCause(), ChimeraFsException.class); |
756 | | - Throwables.throwIfInstanceOf(e.getCause(), DataAccessException.class); |
757 | | - Throwables.throwIfUnchecked(e.getCause()); |
| 750 | + } catch (RuntimeException e) { |
| 751 | + if (e.getCause() != null) { |
| 752 | + Throwables.throwIfInstanceOf(e.getCause(), ChimeraFsException.class); |
| 753 | + Throwables.throwIfInstanceOf(e.getCause(), DataAccessException.class); |
| 754 | + Throwables.throwIfUnchecked(e.getCause()); |
| 755 | + } |
758 | 756 | throw new RuntimeException(e.getCause()); |
759 | 757 | } |
760 | 758 | } else { |
@@ -1403,19 +1401,19 @@ private static void checkNameLength(String name) throws InvalidNameChimeraExcept |
1403 | 1401 | } |
1404 | 1402 |
|
1405 | 1403 | @Override |
1406 | | - public void updateFsStat() throws ChimeraFsException { |
| 1404 | + public void updateFsStat() { |
1407 | 1405 | _sqlDriver.updateFsStat(); |
1408 | 1406 | } |
1409 | 1407 |
|
1410 | | - public FsStat getFsStat0() throws ChimeraFsException { |
| 1408 | + public FsStat getFsStat0() { |
1411 | 1409 | return _sqlDriver.getFsStat(); |
1412 | 1410 | } |
1413 | 1411 |
|
1414 | 1412 | @Override |
1415 | 1413 | public FsStat getFsStat() throws ChimeraFsException { |
1416 | 1414 | try { |
1417 | | - return _fsStatCache.get(DUMMY_KEY); |
1418 | | - } catch (ExecutionException e) { |
| 1415 | + return _fsStatCache.synchronous().get(DUMMY_KEY); |
| 1416 | + } catch (CompletionException e) { |
1419 | 1417 | Throwable t = e.getCause(); |
1420 | 1418 | Throwables.propagateIfPossible(t, ChimeraFsException.class); |
1421 | 1419 | throw new ChimeraFsException(t.getMessage(), t); |
|
0 commit comments