/** * Add a replica's meta information into the map * * @param bpid block pool id * @param replicaInfo a replica's meta information * @return previous meta information of the replica * @throws IllegalArgumentException if the input parameter is null */ ReplicaInfo add(String bpid, ReplicaInfo replicaInfo) { checkBlockPool(bpid); checkBlock(replicaInfo); try (AutoCloseableLock l = lock.acquire()) { FoldedTreeSet<ReplicaInfo> set = map.get(bpid); if (set == null) { // Add an entry for block pool if it does not exist already set = new FoldedTreeSet<>(); map.put(bpid, set); } return set.addOrReplace(replicaInfo); } }
/** * Get the meta information of the replica that matches both block id * and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the replica's meta information * @throws IllegalArgumentException if the input block or block pool is null */ ReplicaInfo get(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); ReplicaInfo replicaInfo = get(bpid, block.getBlockId()); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return replicaInfo; } return null; }
/** * Add a replica's meta information into the map, if already exist * return the old replicaInfo. */ ReplicaInfo addAndGet(String bpid, ReplicaInfo replicaInfo) { checkBlockPool(bpid); checkBlock(replicaInfo); try (AutoCloseableLock l = lock.acquire()) { FoldedTreeSet<ReplicaInfo> set = map.get(bpid); if (set == null) { // Add an entry for block pool if it does not exist already set = new FoldedTreeSet<>(); map.put(bpid, set); } ReplicaInfo oldReplicaInfo = set.get(replicaInfo.getBlockId(), LONG_AND_BLOCK_COMPARATOR); if (oldReplicaInfo != null) { return oldReplicaInfo; } else { set.addOrReplace(replicaInfo); } return replicaInfo; } }
/** * Remove the replica's meta information from the map that matches * the input block's id and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the removed replica's meta information * @throws IllegalArgumentException if the input block is null */ ReplicaInfo remove(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); try (AutoCloseableLock l = lock.acquire()) { FoldedTreeSet<ReplicaInfo> set = map.get(bpid); if (set != null) { ReplicaInfo replicaInfo = set.get(block.getBlockId(), LONG_AND_BLOCK_COMPARATOR); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return set.removeAndGet(replicaInfo); } } } return null; }
/** * Add a replica's meta information into the map * * @param bpid block pool id * @param replicaInfo a replica's meta information * @return previous meta information of the replica * @throws IllegalArgumentException if the input parameter is null */ ReplicaInfo add(String bpid, ReplicaInfo replicaInfo) { checkBlockPool(bpid); checkBlock(replicaInfo); synchronized(mutex) { Map<Long, ReplicaInfo> m = map.get(bpid); if (m == null) { // Add an entry for block pool if it does not exist already m = new HashMap<Long, ReplicaInfo>(); map.put(bpid, m); } return m.put(replicaInfo.getBlockId(), replicaInfo); } }
/** * Add a replica's meta information into the map * * @param bpid block pool id * @param replicaInfo a replica's meta information * @return previous meta information of the replica * @throws IllegalArgumentException if the input parameter is null */ ReplicaInfo add(String bpid, ReplicaInfo replicaInfo) { checkBlockPool(bpid); checkBlock(replicaInfo); synchronized(mutex) { Map<Long, ReplicaInfo> m = map.get(bpid); if (m == null) { // Add an entry for block pool if it does not exist already m = new HashMap<Long, ReplicaInfo>(); map.put(bpid, m); } return m.put(replicaInfo.getBlockId(), replicaInfo); } }
/** * Remove the replica's meta information from the map that matches * the input block's id and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the removed replica's meta information * @throws IllegalArgumentException if the input block is null */ ReplicaInfo remove(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); synchronized(mutex) { Map<Long, ReplicaInfo> m = map.get(bpid); if (m != null) { Long key = Long.valueOf(block.getBlockId()); ReplicaInfo replicaInfo = m.get(key); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return m.remove(key); } } } return null; }
/** * Remove the replica's meta information from the map that matches * the input block's id and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the removed replica's meta information * @throws IllegalArgumentException if the input block is null */ ReplicaInfo remove(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); synchronized(mutex) { Map<Long, ReplicaInfo> m = map.get(bpid); if (m != null) { Long key = Long.valueOf(block.getBlockId()); ReplicaInfo replicaInfo = m.get(key); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return m.remove(key); } } } return null; }
/** * Get the meta information of the replica that matches both block id * and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the replica's meta information * @throws IllegalArgumentException if the input block or block pool is null */ ReplicaInfo get(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); ReplicaInfo replicaInfo = get(bpid, block.getBlockId()); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return replicaInfo; } return null; }
/** * Get the meta information of the replica that matches both block id * and generation stamp * @param bpid block pool id * @param block block with its id as the key * @return the replica's meta information * @throws IllegalArgumentException if the input block or block pool is null */ ReplicaInfo get(String bpid, Block block) { checkBlockPool(bpid); checkBlock(block); ReplicaInfo replicaInfo = get(bpid, block.getBlockId()); if (replicaInfo != null && block.getGenerationStamp() == replicaInfo.getGenerationStamp()) { return replicaInfo; } return null; }