Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public DefaultTableRuntimeStore(
Preconditions.checkNotNull(tableIdentifier, "ServerTableIdentifier must not be null.");
Preconditions.checkNotNull(meta, "TableRuntimeMeta must not be null.");
Preconditions.checkNotNull(requiredStates, "requiredStates must not be null.");
Preconditions.checkNotNull(restoredStates, "restoredStates must not be null.");
this.tableIdentifier = tableIdentifier;
this.meta = meta;
restoreStates(requiredStates, restoredStates);
Expand Down Expand Up @@ -136,37 +135,41 @@ public TableRuntimeOperation begin() {

protected void restoreStates(
List<StateKey<?>> requiredStates, List<TableRuntimeState> restoredStates) {
Map<String, TableRuntimeState> stateMap =
restoredStates.stream()
.collect(Collectors.toMap(TableRuntimeState::getStateKey, Function.identity()));

requiredStates.forEach(
key -> {
if (stateMap.containsKey(key.getKey())) {
states.put(key.getKey(), stateMap.get(key.getKey()));
stateMap.remove(key.getKey());
} else {
doAs(
TableRuntimeMapper.class,
mapper ->
mapper.saveState(
tableIdentifier.getId(), key.getKey(), key.serializeDefault()));
TableRuntimeState state =
getAs(
TableRuntimeMapper.class,
m -> m.getState(tableIdentifier.getId(), key.getKey()));
Preconditions.checkNotNull(state, "State %s initialize failed", key.getKey());
states.put(key.getKey(), state);
}
});

if (!stateMap.isEmpty()) {
LOG.warn("Found {} useless runtime states for {}", stateMap.size(), tableIdentifier);
stateMap.forEach(
(k, s) -> {
LOG.warn("Remove useless runtime state {} for {}", k, tableIdentifier);
doAs(TableRuntimeMapper.class, m -> m.removeState(s.getStateId()));
if (restoredStates == null) {
doAs(TableRuntimeMapper.class, m -> m.saveState(meta.getTableId(), null, null));
} else {
Map<String, TableRuntimeState> stateMap =
restoredStates.stream()
.collect(Collectors.toMap(TableRuntimeState::getStateKey, Function.identity()));

requiredStates.forEach(
key -> {
if (stateMap.containsKey(key.getKey())) {
states.put(key.getKey(), stateMap.get(key.getKey()));
stateMap.remove(key.getKey());
} else {
doAs(
TableRuntimeMapper.class,
mapper ->
mapper.saveState(
tableIdentifier.getId(), key.getKey(), key.serializeDefault()));
TableRuntimeState state =
getAs(
TableRuntimeMapper.class,
m -> m.getState(tableIdentifier.getId(), key.getKey()));
Preconditions.checkNotNull(state, "State %s initialize failed", key.getKey());
states.put(key.getKey(), state);
}
});

if (!stateMap.isEmpty()) {
LOG.warn("Found {} useless runtime states for {}", stateMap.size(), tableIdentifier);
stateMap.forEach(
(k, s) -> {
LOG.warn("Remove useless runtime state {} for {}", k, tableIdentifier);
doAs(TableRuntimeMapper.class, m -> m.removeState(s.getStateId()));
});
}
}
}

Expand Down
Loading