/** * Parse a given cluster state string into a returned ClusterState instance, wrapping any * parse exceptions in a RuntimeException. */ public static ClusterState stateFromString(final String stateStr) { try { return new ClusterState(stateStr); } catch (Exception e) { throw new RuntimeException(e); } }
public ClusterStateImpl(byte[] serialized) throws ParseException { ByteBuffer buf = ByteBuffer.wrap(serialized); int clusterStateLength = buf.getInt(); byte[] clusterState = new byte[clusterStateLength]; buf.get(clusterState); clusterIndex = buf.getShort(); int distributionLength = buf.getInt(); byte[] distribution = new byte[distributionLength]; buf.get(distribution); this.clusterState = new com.yahoo.vdslib.state.ClusterState(new String(clusterState)); this.distribution = new Distribution("raw:" + new String(distribution)); }
private static Optional<ClusterState> clusterStateFromReply(final WrongDistributionReply reply) { try { return Optional.of(new ClusterState(reply.getSystemState())); } catch (Exception e) { reply.getTrace().trace(1, "Error when parsing system state string " + reply.getSystemState()); return Optional.empty(); } }
private void handleWrongDistributionReply(WrongDistributionReply reply) { try { ClusterState newState = new ClusterState(reply.getSystemState()); int stateBits = newState.getDistributionBitCount(); if (stateBits != progress.getIterator().getDistributionBitCount()) { log.log(LogLevel.DEBUG, "System state changed; now at " + stateBits + " distribution bits"); // Update the internal state of the visitor iterator. If we're increasing // the number of distribution bits, this may lead to splitting of pending // buckets. If we're decreasing, it may lead to merging of pending buckets // and potential loss of sub-bucket progress. In either way, the iterator // will not let any new buckets out before all active buckets have been // updated. progress.getIterator().setDistributionBitCount(stateBits); } } catch (Exception e) { log.log(LogLevel.ERROR, "Failed to parse new system state string: " + reply.getSystemState()); transitionTo(new StateDescription(State.FAILED, "Failed to parse cluster state '" + reply.getSystemState() + "'")); } }