SHA256
Починить восстановление blockchain_state при full resync
This commit is contained in:
@@ -138,6 +138,54 @@ public final class BlockchainStateDAO {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Строгая вставка state только если записи ещё нет.
|
||||
*
|
||||
* Нужна для recovery / resync:
|
||||
* - identity пользователя уже может существовать в solana_users;
|
||||
* - в таком случае нам надо восстановить только blockchain_state;
|
||||
* - если запись уже есть, метод просто ничего не меняет.
|
||||
*/
|
||||
public boolean insertIfMissing(Connection c, BlockchainStateEntry e) throws SQLException {
|
||||
String sql = """
|
||||
INSERT INTO blockchain_state (
|
||||
blockchain_name,
|
||||
login,
|
||||
blockchain_key,
|
||||
size_limit,
|
||||
file_size_bytes,
|
||||
last_block_number,
|
||||
last_block_hash,
|
||||
updated_at_ms
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(blockchain_name) DO NOTHING
|
||||
""";
|
||||
|
||||
try (PreparedStatement ps = c.prepareStatement(sql)) {
|
||||
int i = 1;
|
||||
|
||||
ps.setString(i++, e.getBlockchainName());
|
||||
ps.setString(i++, nn(e.getLogin()));
|
||||
ps.setString(i++, nn(e.getBlockchainKey()));
|
||||
|
||||
ps.setLong(i++, e.getSizeLimit());
|
||||
ps.setLong(i++, e.getFileSizeBytes());
|
||||
|
||||
ps.setInt(i++, e.getLastBlockNumber());
|
||||
setBytesNullable(ps, i++, e.getLastBlockHash());
|
||||
|
||||
ps.setLong(i++, e.getUpdatedAtMs());
|
||||
|
||||
return ps.executeUpdate() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean insertIfMissing(BlockchainStateEntry e) throws SQLException {
|
||||
try (Connection c = db.getConnection()) {
|
||||
return insertIfMissing(c, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Атомарно увеличить file_size_bytes на deltaBytes, но только если НЕ превысим size_limit.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user