@Override public void setFutureLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = assignment.server.getLocation() + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new DistributedStoreException( "Trying to set the root tablet location: it is already set to " + current.current); } store.put(RootTable.ZROOT_TABLET_FUTURE_LOCATION, value.getBytes(UTF_8)); }
@Override public void setLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = assignment.server.getLocation() + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new DistributedStoreException( "Trying to set the root tablet location: it is already set to " + current.current); } if (!current.future.equals(assignment.server)) { throw new DistributedStoreException("Root tablet is already assigned to " + current.future); } store.put(RootTable.ZROOT_TABLET_LOCATION, value.getBytes(UTF_8)); store.put(RootTable.ZROOT_TABLET_LAST_LOCATION, value.getBytes(UTF_8)); // Make the following unnecessary by making the entire update atomic store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("Put down root tablet location"); }
@Override public void unassign(Collection<TabletLocationState> tablets, Map<TServerInstance,List<Path>> logsForDeadServers) throws DistributedStoreException { if (tablets.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); TabletLocationState tls = tablets.iterator().next(); if (tls.extent.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); if (logsForDeadServers != null) { List<Path> logs = logsForDeadServers.get(tls.futureOrCurrent()); if (logs != null) { for (Path entry : logs) { LogEntry logEntry = new LogEntry(RootTable.EXTENT, System.currentTimeMillis(), tls.futureOrCurrent().getLocation().toString(), entry.toString()); byte[] value; try { value = logEntry.toBytes(); } catch (IOException ex) { throw new DistributedStoreException(ex); } store.put(RootTable.ZROOT_TABLET_WALOGS + "/" + logEntry.getUniqueID(), value); } } } store.remove(RootTable.ZROOT_TABLET_LOCATION); store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("unassign root tablet location"); }
@Override public void setFutureLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(Constants.ROOT_TABLET_EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = AddressUtil.toString(assignment.server.getLocation()) + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new IllegalDSException("Trying to set the root tablet location: it is already set to " + current.current); } store.put(Constants.ZROOT_TABLET_FUTURE_LOCATION, value.getBytes(UTF_8)); }
@Override public void setFutureLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = assignment.server.getLocation() + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new DistributedStoreException( "Trying to set the root tablet location: it is already set to " + current.current); } store.put(RootTable.ZROOT_TABLET_FUTURE_LOCATION, value.getBytes(UTF_8)); }
@Override public void setLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = assignment.server.getLocation() + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new DistributedStoreException( "Trying to set the root tablet location: it is already set to " + current.current); } if (!current.future.equals(assignment.server)) { throw new DistributedStoreException("Root tablet is already assigned to " + current.future); } store.put(RootTable.ZROOT_TABLET_LOCATION, value.getBytes(UTF_8)); store.put(RootTable.ZROOT_TABLET_LAST_LOCATION, value.getBytes(UTF_8)); // Make the following unnecessary by making the entire update atomic store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("Put down root tablet location"); }
@Override public void setLocations(Collection<Assignment> assignments) throws DistributedStoreException { if (assignments.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); Assignment assignment = assignments.iterator().next(); if (assignment.tablet.compareTo(Constants.ROOT_TABLET_EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); String value = AddressUtil.toString(assignment.server.getLocation()) + "|" + assignment.server.getSession(); Iterator<TabletLocationState> currentIter = iterator(); TabletLocationState current = currentIter.next(); if (current.current != null) { throw new IllegalDSException("Trying to set the root tablet location: it is already set to " + current.current); } if (!current.future.equals(assignment.server)) { throw new IllegalDSException("Root tablet is already assigned to " + current.future); } store.put(Constants.ZROOT_TABLET_LOCATION, value.getBytes(UTF_8)); store.put(Constants.ZROOT_TABLET_LAST_LOCATION, value.getBytes(UTF_8)); // Make the following unnecessary by making the entire update atomic store.remove(Constants.ZROOT_TABLET_FUTURE_LOCATION); log.debug("Put down root tablet location"); }
@Override public void unassign(Collection<TabletLocationState> tablets, Map<TServerInstance,List<Path>> logsForDeadServers) throws DistributedStoreException { if (tablets.size() != 1) throw new IllegalArgumentException("There is only one root tablet"); TabletLocationState tls = tablets.iterator().next(); if (tls.extent.compareTo(RootTable.EXTENT) != 0) throw new IllegalArgumentException("You can only store the root tablet location"); if (logsForDeadServers != null) { List<Path> logs = logsForDeadServers.get(tls.futureOrCurrent()); if (logs != null) { for (Path entry : logs) { LogEntry logEntry = new LogEntry(RootTable.EXTENT, System.currentTimeMillis(), tls.futureOrCurrent().getLocation().toString(), entry.toString()); byte[] value; try { value = logEntry.toBytes(); } catch (IOException ex) { throw new DistributedStoreException(ex); } store.put(RootTable.ZROOT_TABLET_WALOGS + "/" + logEntry.getUniqueID(), value); } } } store.remove(RootTable.ZROOT_TABLET_LOCATION); store.remove(RootTable.ZROOT_TABLET_FUTURE_LOCATION); log.debug("unassign root tablet location"); }