Search in sources :

Example 1 with DeserializationException

use of com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException in project dble by actiontech.

the class Deserializer method fromJson.

public static CoordinatorLogEntry fromJson(String coordinatorLogEntryStr) throws DeserializationException {
    try {
        String jsonContent = coordinatorLogEntryStr.trim();
        validateJsonContent(jsonContent);
        Map<String, String> header = extractHeader(jsonContent);
        String coordinatorId = header.get(CoordinatorLogEntry.ID);
        String arrayContent = extractArrayPart(jsonContent);
        List<String> elements = tokenize(arrayContent);
        ParticipantLogEntry[] participantLogEntries = new ParticipantLogEntry[elements.size()];
        for (int i = 0; i < participantLogEntries.length; i++) {
            participantLogEntries[i] = recreateParticipantLogEntry(coordinatorId, elements.get(i));
        }
        CoordinatorLogEntry actual = new CoordinatorLogEntry(coordinatorId, participantLogEntries, TxState.valueOf(Integer.parseInt(header.get(CoordinatorLogEntry.STATE))));
        return actual;
    } catch (Exception unexpectedEOF) {
        throw new DeserializationException(coordinatorLogEntryStr);
    }
}
Also used : DeserializationException(com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException) DeserializationException(com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException)

Example 2 with DeserializationException

use of com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException in project dble by actiontech.

the class FileSystemRepository method readContent.

private static Map<String, CoordinatorLogEntry> readContent(BufferedReader br) throws IOException {
    Map<String, CoordinatorLogEntry> coordinatorLogEntries = new HashMap<>();
    try {
        String line;
        while ((line = br.readLine()) != null) {
            CoordinatorLogEntry coordinatorLogEntry = deserialize(line);
            coordinatorLogEntries.put(coordinatorLogEntry.getId(), coordinatorLogEntry);
        }
    } catch (EOFException unexpectedEOF) {
        LOGGER.info("Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
    // merely return what was read so far...
    } catch (ObjectStreamException unexpectedEOF) {
        LOGGER.warn(AlarmCode.CORE_FILE_WRITE_WARN + "Unexpected EOF - logfile not closed properly last time?", unexpectedEOF);
    // merely return what was read so far...
    } catch (DeserializationException unexpectedEOF) {
        LOGGER.warn(AlarmCode.CORE_FILE_WRITE_WARN + "Unexpected EOF - logfile not closed properly last time? " + unexpectedEOF);
    }
    return coordinatorLogEntries;
}
Also used : HashMap(java.util.HashMap) DeserializationException(com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException) CoordinatorLogEntry(com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry)

Example 3 with DeserializationException

use of com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException in project dble by actiontech.

the class KVStoreRepository method getAllCoordinatorLogEntries.

@Override
public Collection<CoordinatorLogEntry> getAllCoordinatorLogEntries() {
    String data = null;
    try {
        if (zkConn.checkExists().forPath(logPath) != null) {
            try {
                byte[] raw = zkConn.getData().forPath(logPath);
                if (raw != null) {
                    data = new String(raw, StandardCharsets.UTF_8);
                }
            } catch (Exception e) {
                LOGGER.warn(AlarmCode.CORE_ZK_WARN + "KVStoreRepository.getAllCoordinatorLogEntries error", e);
            }
        }
    } catch (Exception e2) {
        LOGGER.warn(AlarmCode.CORE_ZK_WARN + "KVStoreRepository error", e2);
    }
    if (data == null) {
        return Collections.emptyList();
    }
    Map<String, CoordinatorLogEntry> coordinatorLogEntries = new HashMap<>();
    String[] logs = data.split(Serializer.LINE_SEPARATOR);
    for (String log : logs) {
        try {
            CoordinatorLogEntry coordinatorLogEntry = Deserializer.fromJson(log);
            coordinatorLogEntries.put(coordinatorLogEntry.getId(), coordinatorLogEntry);
        } catch (DeserializationException e) {
            LOGGER.warn(AlarmCode.CORE_ZK_WARN + "Unexpected EOF - logfile not closed properly last time? ", e);
        }
    }
    return coordinatorLogEntries.values();
}
Also used : HashMap(java.util.HashMap) DeserializationException(com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException) DeserializationException(com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException) CoordinatorLogEntry(com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry)

Aggregations

DeserializationException (com.actiontech.dble.backend.mysql.xa.recovery.DeserializationException)3 CoordinatorLogEntry (com.actiontech.dble.backend.mysql.xa.CoordinatorLogEntry)2 HashMap (java.util.HashMap)2