Сервер: дочистить legacy-слои и доки

This commit is contained in:
AidarKC
2026-07-27 19:29:10 +04:00
parent 0db3c3af5a
commit 6ed91a105e
33 changed files with 127 additions and 165 deletions
@@ -29,7 +29,7 @@ import java.sql.SQLException;
* отдельным recovery/resync-слоем после успешного commit.
*
* Важный смысл текущей реализации:
* - мы НЕ трогаем identity-слой (`solana_users`) и НЕ трогаем DM-таблицы;
* - мы НЕ трогаем current users слой (`solana_user_pda_current`) и НЕ трогаем DM-таблицы;
* - мы очищаем только блокчейн пользователя и derived-state, который строится из неё;
* - висячие cross-chain ссылки в чужих blocks допускаются как нормальное поведение системы.
*/
@@ -142,7 +142,7 @@ public final class BlockchainStateDAO {
* Строгая вставка state только если записи ещё нет.
*
* Нужна для recovery / resync:
* - identity пользователя уже может существовать в solana_users;
* - runtime-проекция пользователя уже может существовать в current users слое;
* - в таком случае нам надо восстановить только blockchain_state;
* - если запись уже есть, метод просто ничего не меняет.
*/
@@ -1,7 +1,7 @@
package shine.db.dao;
import shine.db.DbController;
import shine.db.entities.SignedMessageV2Entry;
import shine.db.entities.SignedMessageEntry;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -11,7 +11,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public final class SignedMessagesV2DAO {
public final class SignedMessagesDAO {
public enum ApplyStatus {
APPLIED,
@@ -24,21 +24,21 @@ public final class SignedMessagesV2DAO {
}
}
private static volatile SignedMessagesV2DAO instance;
private static volatile SignedMessagesDAO instance;
private final DbController db = DbController.getInstance();
private SignedMessagesV2DAO() {}
private SignedMessagesDAO() {}
public static SignedMessagesV2DAO getInstance() {
public static SignedMessagesDAO getInstance() {
if (instance == null) {
synchronized (SignedMessagesV2DAO.class) {
if (instance == null) instance = new SignedMessagesV2DAO();
synchronized (SignedMessagesDAO.class) {
if (instance == null) instance = new SignedMessagesDAO();
}
}
return instance;
}
public ApplyStatus insertIfAbsent(SignedMessageV2Entry e) throws Exception {
public ApplyStatus insertIfAbsent(SignedMessageEntry e) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
if (isBlockedByConversationDelete(c, e.getFromLogin(), e.getToLogin(), e.getTimeMs())) {
@@ -65,7 +65,7 @@ public final class SignedMessagesV2DAO {
});
}
public boolean insertPairBothOrNothing(SignedMessageV2Entry first, SignedMessageV2Entry second) throws Exception {
public boolean insertPairBothOrNothing(SignedMessageEntry first, SignedMessageEntry second) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
boolean prevAutoCommit = c.getAutoCommit();
@@ -94,7 +94,7 @@ public final class SignedMessagesV2DAO {
});
}
public ApplyStatus upsertContentPair(SignedMessageV2Entry incoming, SignedMessageV2Entry outgoing) throws Exception {
public ApplyStatus upsertContentPair(SignedMessageEntry incoming, SignedMessageEntry outgoing) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
boolean prevAutoCommit = c.getAutoCommit();
@@ -135,7 +135,7 @@ public final class SignedMessagesV2DAO {
});
}
public ApplyStatus upsertIncomingCopy(SignedMessageV2Entry incoming) throws Exception {
public ApplyStatus upsertIncomingCopy(SignedMessageEntry incoming) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
boolean prevAutoCommit = c.getAutoCommit();
@@ -172,7 +172,7 @@ public final class SignedMessagesV2DAO {
});
}
public ApplyStatus applyDeleteMessage(SignedMessageV2Entry tombstone) throws Exception {
public ApplyStatus applyDeleteMessage(SignedMessageEntry tombstone) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
boolean prevAutoCommit = c.getAutoCommit();
@@ -203,7 +203,7 @@ public final class SignedMessagesV2DAO {
});
}
public ApplyStatus applyDeleteConversation(SignedMessageV2Entry tombstone) throws Exception {
public ApplyStatus applyDeleteConversation(SignedMessageEntry tombstone) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
boolean prevAutoCommit = c.getAutoCommit();
@@ -231,7 +231,7 @@ public final class SignedMessagesV2DAO {
});
}
public SignedMessageV2Entry getByMessageKey(String messageKey) throws Exception {
public SignedMessageEntry getByMessageKey(String messageKey) throws Exception {
try (Connection c = db.getConnection()) {
String sql = """
SELECT
@@ -252,7 +252,7 @@ public final class SignedMessagesV2DAO {
}
}
public SignedMessageV2Entry getLatestConversationDelete(String fromLogin, String toLogin) throws Exception {
public SignedMessageEntry getLatestConversationDelete(String fromLogin, String toLogin) throws Exception {
try (Connection c = db.getConnection()) {
return getLatestConversationDelete(c, fromLogin, toLogin);
}
@@ -314,7 +314,7 @@ public final class SignedMessagesV2DAO {
});
}
public List<SignedMessageV2Entry> listPendingForSession(String login, String sessionId) throws Exception {
public List<SignedMessageEntry> listPendingForSession(String login, String sessionId) throws Exception {
return withBusyRetry(() -> {
try (Connection c = db.getConnection()) {
String fillSql = """
@@ -354,7 +354,7 @@ public final class SignedMessagesV2DAO {
WHERE d.session_id = ? AND d.delivered = 0
ORDER BY m.time_ms ASC, m.revision_time_ms ASC, m.reencrypted_at_ms ASC, m.created_at_ms ASC
""".formatted(messagesTable());
List<SignedMessageV2Entry> out = new ArrayList<>();
List<SignedMessageEntry> out = new ArrayList<>();
try (PreparedStatement ps = c.prepareStatement(sql)) {
ps.setString(1, sessionId);
try (ResultSet rs = ps.executeQuery()) {
@@ -366,7 +366,7 @@ public final class SignedMessagesV2DAO {
});
}
public List<SignedMessageV2Entry> listConversationPage(
public List<SignedMessageEntry> listConversationPage(
String login,
String peerLogin,
long beforeTimeMs,
@@ -395,7 +395,7 @@ public final class SignedMessagesV2DAO {
ORDER BY time_ms DESC, message_key DESC
LIMIT ?
""".formatted(messagesTable());
List<SignedMessageV2Entry> out = new ArrayList<>();
List<SignedMessageEntry> out = new ArrayList<>();
try (PreparedStatement ps = c.prepareStatement(sql)) {
ps.setString(1, login);
ps.setString(2, login);
@@ -416,7 +416,7 @@ public final class SignedMessagesV2DAO {
}
}
private void upsertMessage(Connection c, SignedMessageV2Entry e) throws SQLException {
private void upsertMessage(Connection c, SignedMessageEntry e) throws SQLException {
String sql = """
INSERT INTO %s (
message_key, base_key, target_login, from_login, to_login,
@@ -448,7 +448,7 @@ public final class SignedMessagesV2DAO {
}
}
private void markMessageReadByReceipt(Connection c, SignedMessageV2Entry entry) throws SQLException {
private void markMessageReadByReceipt(Connection c, SignedMessageEntry entry) throws SQLException {
if (entry == null) return;
int messageType = entry.getMessageType();
if (messageType != 3 && messageType != 4) return;
@@ -552,7 +552,7 @@ public final class SignedMessagesV2DAO {
}
}
private SignedMessageV2Entry getLatestConversationDelete(Connection c, String fromLogin, String toLogin) throws Exception {
private SignedMessageEntry getLatestConversationDelete(Connection c, String fromLogin, String toLogin) throws Exception {
String sql = """
SELECT
message_key, base_key, target_login, from_login, to_login,
@@ -646,7 +646,7 @@ public final class SignedMessagesV2DAO {
}
}
private int insertStrict(Connection c, SignedMessageV2Entry e) throws SQLException {
private int insertStrict(Connection c, SignedMessageEntry e) throws SQLException {
String sql = """
INSERT INTO %s (
message_key, base_key, target_login, from_login, to_login,
@@ -661,7 +661,7 @@ public final class SignedMessagesV2DAO {
}
}
private void bindSignedMessage(PreparedStatement ps, SignedMessageV2Entry e) throws SQLException {
private void bindSignedMessage(PreparedStatement ps, SignedMessageEntry e) throws SQLException {
ps.setString(1, e.getMessageKey());
ps.setString(2, e.getBaseKey());
ps.setString(3, e.getTargetLogin());
@@ -718,8 +718,8 @@ public final class SignedMessagesV2DAO {
return "signed_messages";
}
private SignedMessageV2Entry mapRow(ResultSet rs) throws Exception {
SignedMessageV2Entry e = new SignedMessageV2Entry();
private SignedMessageEntry mapRow(ResultSet rs) throws Exception {
SignedMessageEntry e = new SignedMessageEntry();
e.setMessageKey(rs.getString("message_key"));
e.setBaseKey(rs.getString("base_key"));
e.setTargetLogin(rs.getString("target_login"));
@@ -743,7 +743,7 @@ public final class SignedMessagesV2DAO {
}
private record RevisionMarker(long revisionTimeMs, long reencryptedAtMs) {
private static RevisionMarker of(SignedMessageV2Entry entry) {
private static RevisionMarker of(SignedMessageEntry entry) {
return new RevisionMarker(entry.getRevisionTimeMs(), entry.getReencryptedAtMs());
}
}
@@ -1,6 +1,6 @@
package shine.db.entities;
public class SignedMessageV2Entry {
public class SignedMessageEntry {
private String messageKey;
private String baseKey;
private String targetLogin;