Removes all the cache entries referred to the given client. @param client The client for which we must invalidate everything. @param remote The address of the remote peer, if known, or null.
(final RegionClient client,
final SocketAddress remote)
| 3996 | * @param remote The address of the remote peer, if known, or null. |
| 3997 | */ |
| 3998 | private void removeClientFromCache(final RegionClient client, |
| 3999 | final SocketAddress remote) { |
| 4000 | if (client == rootregion) { |
| 4001 | LOG.info("Lost connection with the " |
| 4002 | + (has_root ? (split_meta ? new String(HBASE98_ROOT_REGION) : new String(ROOT)) : |
| 4003 | (split_meta ? new String(HBASE96_META) : new String(META))) |
| 4004 | + " region"); |
| 4005 | rootregion = null; |
| 4006 | } |
| 4007 | ArrayList<RegionInfo> regions = client2regions.remove(client); |
| 4008 | if (regions != null) { |
| 4009 | // Make a copy so we don't need to synchronize on it while iterating. |
| 4010 | RegionInfo[] regions_copy; |
| 4011 | synchronized (regions) { |
| 4012 | regions_copy = regions.toArray(new RegionInfo[regions.size()]); |
| 4013 | regions = null; |
| 4014 | // If any other thread still has a reference to `regions', their |
| 4015 | // updates will be lost (and we don't care). |
| 4016 | } |
| 4017 | for (final RegionInfo region : regions_copy) { |
| 4018 | final byte[] table = region.table(); |
| 4019 | final byte[] stop_key = region.stopKey(); |
| 4020 | // If stop_key is the empty array: |
| 4021 | // This region is the last region for this table. In order to |
| 4022 | // find the start key of the last region, we append a '\0' byte |
| 4023 | // at the end of the table name and search for the entry with a |
| 4024 | // key right before it. |
| 4025 | // Otherwise: |
| 4026 | // Search for the entry with a key right before the stop_key. |
| 4027 | final byte[] search_key = |
| 4028 | createRegionSearchKey(stop_key.length == 0 |
| 4029 | ? Arrays.copyOf(table, table.length + 1) |
| 4030 | : table, stop_key); |
| 4031 | final Map.Entry<byte[], RegionInfo> entry = |
| 4032 | regions_cache.lowerEntry(search_key); |
| 4033 | if (entry != null && entry.getValue() == region) { |
| 4034 | // Invalidate the regions cache first, as it's the most damaging |
| 4035 | // one if it contains stale data. |
| 4036 | regions_cache.remove(entry.getKey()); |
| 4037 | LOG.debug("Removed from regions cache: {}", region); |
| 4038 | } |
| 4039 | final RegionClient oldclient = region2client.remove(region); |
| 4040 | if (client == oldclient) { |
| 4041 | LOG.debug("Association removed: {} -> {}", region, client); |
| 4042 | } else if (oldclient != null) { // Didn't remove what we expected?! |
| 4043 | LOG.warn("When handling disconnection of " + client |
| 4044 | + " and removing " + region + " from region2client" |
| 4045 | + ", it was found that " + oldclient + " was in fact" |
| 4046 | + " serving this region"); |
| 4047 | } |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | if (remote == null) { |
| 4052 | return; // Can't continue without knowing the remote address. |
| 4053 | } |
| 4054 | |
| 4055 | String hostport = null; |
no test coverage detected