SHA256
Восстановить сообщения дублированного канала
This commit is contained in:
@@ -71,6 +71,22 @@ public final class ChannelNameStateDAO {
|
|||||||
ava_size,
|
ava_size,
|
||||||
meta_updated_at_ms
|
meta_updated_at_ms
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
ON CONFLICT (owner_bch_name, channel_type_code, slug) DO UPDATE SET
|
||||||
|
display_name = EXCLUDED.display_name,
|
||||||
|
channel_description = EXCLUDED.channel_description,
|
||||||
|
owner_login = EXCLUDED.owner_login,
|
||||||
|
channel_type_version = EXCLUDED.channel_type_version,
|
||||||
|
channel_root_block_number = EXCLUDED.channel_root_block_number,
|
||||||
|
channel_root_block_hash = EXCLUDED.channel_root_block_hash,
|
||||||
|
created_at_ms = EXCLUDED.created_at_ms,
|
||||||
|
ava_ar = EXCLUDED.ava_ar,
|
||||||
|
ava_pr = EXCLUDED.ava_pr,
|
||||||
|
ava_size = EXCLUDED.ava_size,
|
||||||
|
meta_updated_at_ms = EXCLUDED.meta_updated_at_ms,
|
||||||
|
is_deleted = FALSE,
|
||||||
|
deleted_at_ms = 0,
|
||||||
|
deleted_block_number = NULL
|
||||||
|
WHERE EXCLUDED.channel_root_block_number > channel_names_state.channel_root_block_number
|
||||||
""";
|
""";
|
||||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||||
ps.setString(1, entry.getSlug());
|
ps.setString(1, entry.getSlug());
|
||||||
|
|||||||
+41
-11
@@ -41,7 +41,8 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
private static void rebuildFromBlocksOrThrow() {
|
private static void rebuildFromBlocksOrThrow() {
|
||||||
ChannelNameStateDAO dao = ChannelNameStateDAO.getInstance();
|
ChannelNameStateDAO dao = ChannelNameStateDAO.getInstance();
|
||||||
List<ChannelNameStateEntry> entries = new ArrayList<>();
|
List<ChannelNameStateEntry> entries = new ArrayList<>();
|
||||||
Map<String, String> slugToIdentity = new LinkedHashMap<>();
|
Map<String, ChannelNameStateEntry> entriesByOwnerTypeSlug = new LinkedHashMap<>();
|
||||||
|
Map<ChannelRoot, ChannelNameStateEntry> replacedRoots = new LinkedHashMap<>();
|
||||||
List<String> conflicts = new ArrayList<>();
|
List<String> conflicts = new ArrayList<>();
|
||||||
List<String> skipped = new ArrayList<>();
|
List<String> skipped = new ArrayList<>();
|
||||||
|
|
||||||
@@ -108,14 +109,6 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
String identity = ownerBch + "#" + blockNumber;
|
|
||||||
String ownerTypeSlug = ownerLogin.toLowerCase(Locale.ROOT) + "|" + channelTypeCode + "|" + slug;
|
|
||||||
String existing = slugToIdentity.putIfAbsent(ownerTypeSlug, identity);
|
|
||||||
if (existing != null && !existing.equals(identity)) {
|
|
||||||
conflicts.add("owner/type/slug=\"" + ownerTypeSlug + "\" conflicts: " + existing + " vs " + identity);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelNameStateEntry entry = new ChannelNameStateEntry();
|
ChannelNameStateEntry entry = new ChannelNameStateEntry();
|
||||||
entry.setSlug(slug);
|
entry.setSlug(slug);
|
||||||
entry.setDisplayName(displayName);
|
entry.setDisplayName(displayName);
|
||||||
@@ -131,13 +124,23 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
entry.setChannelRootBlockNumber(blockNumber);
|
entry.setChannelRootBlockNumber(blockNumber);
|
||||||
entry.setChannelRootBlockHash(blockHash);
|
entry.setChannelRootBlockHash(blockHash);
|
||||||
entry.setCreatedAtMs(parsed.timestamp * 1000L);
|
entry.setCreatedAtMs(parsed.timestamp * 1000L);
|
||||||
entries.add(entry);
|
String ownerTypeSlug = ownerLogin.toLowerCase(Locale.ROOT) + "|" + channelTypeCode + "|" + slug;
|
||||||
|
ChannelNameStateEntry previous = entriesByOwnerTypeSlug.put(ownerTypeSlug, entry);
|
||||||
|
if (previous != null) {
|
||||||
|
replacedRoots.put(new ChannelRoot(previous.getOwnerBlockchainName(), previous.getChannelRootBlockNumber(), previous.getChannelRootBlockHash()), entry);
|
||||||
|
conflicts.add("owner/type/slug=\"" + ownerTypeSlug + "\" conflicts: "
|
||||||
|
+ previous.getOwnerBlockchainName() + "#" + previous.getChannelRootBlockNumber()
|
||||||
|
+ " vs " + ownerBch + "#" + blockNumber + "; kept newest root");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entries.addAll(entriesByOwnerTypeSlug.values());
|
||||||
|
|
||||||
dao.clearAll(c);
|
dao.clearAll(c);
|
||||||
dao.insertAll(c, entries);
|
dao.insertAll(c, entries);
|
||||||
|
redirectFollowedChannelRoots(c, replacedRoots);
|
||||||
|
|
||||||
applyMetaUpdates(c, dao, entries, skipped);
|
applyMetaUpdates(c, dao, entries, skipped);
|
||||||
applyDeletionStates(c, dao, skipped);
|
applyDeletionStates(c, dao, skipped);
|
||||||
@@ -155,7 +158,7 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
c.commit();
|
c.commit();
|
||||||
log.info("channel_names_state bootstrapped: {}", entries.size());
|
log.info("channel_names_state bootstrapped: {}", entries.size());
|
||||||
if (!conflicts.isEmpty()) {
|
if (!conflicts.isEmpty()) {
|
||||||
log.warn("channel_names_state bootstrap detected {} slug conflicts (kept first occurrence)", conflicts.size());
|
log.warn("channel_names_state bootstrap detected {} slug conflicts (kept newest root)", conflicts.size());
|
||||||
int preview = Math.min(conflicts.size(), 10);
|
int preview = Math.min(conflicts.size(), 10);
|
||||||
for (int i = 0; i < preview; i++) {
|
for (int i = 0; i < preview; i++) {
|
||||||
log.warn("channel_names_state conflict: {}", conflicts.get(i));
|
log.warn("channel_names_state conflict: {}", conflicts.get(i));
|
||||||
@@ -185,6 +188,31 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Connections are a mutable projection. Keep follows on the current root when a legacy duplicate is replaced. */
|
||||||
|
private static void redirectFollowedChannelRoots(Connection c,
|
||||||
|
Map<ChannelRoot, ChannelNameStateEntry> replacedRoots) throws Exception {
|
||||||
|
String sql = """
|
||||||
|
UPDATE connections_state
|
||||||
|
SET to_block_number = ?, to_block_hash = ?
|
||||||
|
WHERE LOWER(to_login) = LOWER(?)
|
||||||
|
AND to_block_number = ?
|
||||||
|
AND to_block_hash = ?
|
||||||
|
""";
|
||||||
|
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||||
|
for (Map.Entry<ChannelRoot, ChannelNameStateEntry> replacement : replacedRoots.entrySet()) {
|
||||||
|
ChannelRoot oldRoot = replacement.getKey();
|
||||||
|
ChannelNameStateEntry current = replacement.getValue();
|
||||||
|
ps.setInt(1, current.getChannelRootBlockNumber());
|
||||||
|
ps.setBytes(2, current.getChannelRootBlockHash());
|
||||||
|
ps.setString(3, current.getOwnerLogin());
|
||||||
|
ps.setInt(4, oldRoot.blockNumber());
|
||||||
|
ps.setBytes(5, oldRoot.blockHash());
|
||||||
|
ps.addBatch();
|
||||||
|
}
|
||||||
|
ps.executeBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void applyDeletionStates(Connection c, ChannelNameStateDAO dao, List<String> skipped) throws Exception {
|
private static void applyDeletionStates(Connection c, ChannelNameStateDAO dao, List<String> skipped) throws Exception {
|
||||||
String sql = """
|
String sql = """
|
||||||
SELECT bch_name, block_number, block_bytes, msg_sub_type
|
SELECT bch_name, block_number, block_bytes, msg_sub_type
|
||||||
@@ -219,6 +247,8 @@ public final class ChannelNamesStateBootstrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record ChannelRoot(String ownerBlockchainName, int blockNumber, byte[] blockHash) {}
|
||||||
|
|
||||||
private static void applyMetaUpdates(Connection c,
|
private static void applyMetaUpdates(Connection c,
|
||||||
ChannelNameStateDAO dao,
|
ChannelNameStateDAO dao,
|
||||||
List<ChannelNameStateEntry> entries,
|
List<ChannelNameStateEntry> entries,
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
client.version=1.20.67
|
client.version=1.20.67
|
||||||
server.version=1.16.34
|
server.version=1.16.36
|
||||||
|
|||||||
Reference in New Issue
Block a user