}
}
@Override
protected OnlineCache buildOnlineCache(Session session) {
Exchange ex = schemaTreeExchange(session);
try{
OnlineCache onlineCache = new OnlineCache();
// Load affected schemas, then remaining schemas and create full AIS.
ex.clear().append(S_K_ONLINE).append(Key.BEFORE);
while(ex.next()) {
long onlineID = ex.getKey().indexTo(-1).decodeLong();
long generation = ex.getValue().getLong();
int schemaCount = 0;
ex.append(S_K_PROTOBUF).append(Key.BEFORE);
while(ex.next()) {
++schemaCount;
String schema = ex.getKey().indexTo(-1).decodeString();
Long prev = onlineCache.schemaToOnline.put(schema, onlineID);
assert (prev == null) : String.format("%s, %d, %d", schema, prev, onlineID);
}
ex.getKey().cut();
if(generation != -1) {
ProtobufReader reader = new ProtobufReader(getTypesRegistry(), getStorageFormatRegistry());
loadProtobufChildren(ex, reader, null);
loadPrimaryProtobuf(ex, reader, onlineCache.schemaToOnline.keySet());
// Reader will have two copies of affected schemas, skip second (i.e. non-online)
AkibanInformationSchema newAIS = finishReader(reader);
validateAndFreeze(newAIS, generation);
buildRowDefs(session, newAIS);
onlineCache.onlineToAIS.put(onlineID, newAIS);
} else if(schemaCount != 0) {
throw new IllegalStateException("No generation but had schemas");
}
ex.clear().append(S_K_ONLINE).append(onlineID).append(S_K_CHANGE).append(Key.BEFORE);
while(ex.next()) {
int tid = ex.getKey().indexTo(-1).decodeInt();
Long prev = onlineCache.tableToOnline.put(tid, onlineID);
assert (prev == null) : String.format("%d, %d, %d", tid, prev, onlineID);
TableChanges.ChangeSet changeSet = ChangeSetHelper.load(ex.getValue().getByteArray());
onlineCache.onlineToChangeSets.put(onlineID, changeSet);
}
ex.clear().append(S_K_ONLINE).append(onlineID);
}
return onlineCache;
} catch(PersistitException | RollbackException e) {
throw wrapPersistitException(session, e);