Skip to content

Commit

Permalink
0002321: Add dump of outgoing and incoming batches to the support sna…
Browse files Browse the repository at this point in the history
…pshot
  • Loading branch information
chenson42 committed Jun 18, 2015
1 parent ac1e99f commit 7f4681a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 23 deletions.
Expand Up @@ -183,29 +183,38 @@ public static File createSnapshot(ISymmetricEngine engine) {
IOUtils.closeQuietly(fos);
}

fos = null;
try {
fos = new FileOutputStream(new File(tmpDir, "runtime-data.xml"));
DbExport export = new DbExport(engine.getDatabasePlatform());
export.setFormat(Format.XML);
export.setNoCreateInfo(true);
String tablePrefix = engine.getTablePrefix();
export.exportTables(
fos,
new String[] {
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_IDENTITY),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_SECURITY),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_TRIGGER_HIST),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_LOCK),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_COMMUNICATION)});
} catch (IOException e) {
log.warn("Failed to export table definitions", e);
} finally {
IOUtils.closeQuietly(fos);
}
String tablePrefix = engine.getTablePrefix();

DbExport export = new DbExport(engine.getDatabasePlatform());
export.setFormat(Format.CSV);
export.setNoCreateInfo(true);

extract(export, new File(tmpDir, "identity.csv"), TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_IDENTITY));

extract(export, new File(tmpDir, "node.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE));

extract(export, new File(tmpDir, "nodesecurity.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_SECURITY));

extract(export, new File(tmpDir, "nodehost.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_HOST));

extract(export, new File(tmpDir, "triggerhist.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_TRIGGER_HIST));

extract(export, new File(tmpDir, "lock.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_LOCK));

extract(export, new File(tmpDir, "nodecommunication.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_NODE_COMMUNICATION));

extract(export, 5000, new File(tmpDir, "outgoingbatch.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_OUTGOING_BATCH));

extract(export, 5000, new File(tmpDir, "incomingbatch.csv"),
TableConstants.getTableName(tablePrefix, TableConstants.SYM_INCOMING_BATCH));

final int THREAD_INDENT_SPACE = 50;
fwriter = null;
try {
Expand Down Expand Up @@ -320,6 +329,25 @@ public static File createSnapshot(ISymmetricEngine engine) {
}
}

protected static void extract(DbExport export, File file, String... tables) {
extract(export, Integer.MAX_VALUE, file, tables);
}

protected static void extract(DbExport export, int maxRows, File file, String... tables) {
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
export.setMaxRows(maxRows);
export.exportTables(
fos,
tables);
} catch (IOException e) {
log.warn("Failed to export table definitions", e);
} finally {
IOUtils.closeQuietly(fos);
}
}

protected static void writeDirectoryListing(ISymmetricEngine engine, File tmpDir) {
try {
File home = new File(System.getProperty("user.dir"));
Expand Down
Expand Up @@ -94,6 +94,8 @@ public enum Compatible {
private String schema;

private String dir;

private int maxRows = Integer.MAX_VALUE;

private boolean useQuotedIdentifiers = true;

Expand Down Expand Up @@ -218,8 +220,12 @@ protected void writeTable(final WriterWrapper writerWrapper, Table table, String
}

platform.getSqlTemplate().query(sql, new ISqlRowMapper<Object>() {
int rows = maxRows;
public Object mapRow(Row row) {
writerWrapper.writeRow(row);
if (rows > 0) {
writerWrapper.writeRow(row);
rows--;
}
return Boolean.TRUE;
}
});
Expand Down Expand Up @@ -381,6 +387,14 @@ public void setUseJdbcTimestampFormat(boolean useJdbcTimestampFormat) {
public boolean isUseJdbcTimestampFormat() {
return useJdbcTimestampFormat;
}

public void setMaxRows(int maxRows) {
this.maxRows = maxRows;
}

public int getMaxRows() {
return maxRows;
}

class WriterWrapper {
final private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Expand Down

0 comments on commit 7f4681a

Please sign in to comment.