Skip to content

add new interfaces to P2P Mode #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static void main(String[] args) {
SimpleTest.run();
ParallelWriteTest.run();
MultiNodeWriteTest.run();
P2PModeWriteTest.run();
SimpleAbortTest.run();
P2PModeAbortTest.run();
}

private static void prepareTestTable() throws Exception {
Expand Down Expand Up @@ -105,16 +108,16 @@ private static ObDirectLoadConnection buildConnection(int writeThreadNum)
.enableParallelWrite(writeThreadNum).build();
}

private static ObDirectLoadStatement buildStatement(ObDirectLoadConnection connection)
private static ObDirectLoadStatement buildStatement(ObDirectLoadConnection connection, boolean isP2PMode)
throws ObDirectLoadException {
return connection.getStatementBuilder().setTableName(tableName).setDupAction(dupAction)
.setParallel(parallel).setQueryTimeout(timeout).build();
.setParallel(parallel).setQueryTimeout(timeout).setIsP2PMode(isP2PMode).build();
}

private static ObDirectLoadStatement buildStatement(ObDirectLoadConnection connection, ObDirectLoadStatementExecutionId executionId)
private static ObDirectLoadStatement buildStatement(ObDirectLoadConnection connection, ObDirectLoadStatementExecutionId executionId, boolean isP2PMode)
throws ObDirectLoadException {
return connection.getStatementBuilder().setTableName(tableName).setDupAction(dupAction)
.setParallel(parallel).setQueryTimeout(timeout).setExecutionId(executionId).build();
.setParallel(parallel).setQueryTimeout(timeout).setExecutionId(executionId).setIsP2PMode(isP2PMode).build();
}

private static class SimpleTest {
Expand All @@ -127,7 +130,7 @@ public static void run() {
prepareTestTable();

connection = buildConnection(1);
statement = buildStatement(connection);
statement = buildStatement(connection, false);

statement.begin();

Expand Down Expand Up @@ -192,7 +195,7 @@ public static void run() {
prepareTestTable();

connection = buildConnection(parallel);
statement = buildStatement(connection);
statement = buildStatement(connection, false);

statement.begin();

Expand Down Expand Up @@ -246,7 +249,7 @@ public void run() {
executionId.decode(executionIdBytes);

connection = buildConnection(1);
statement = buildStatement(connection, executionId);
statement = buildStatement(connection, executionId, false);

ObDirectLoadBucket bucket = new ObDirectLoadBucket();
ObObj[] rowObjs = new ObObj[2];
Expand Down Expand Up @@ -277,7 +280,7 @@ public static void run() {
prepareTestTable();

connection = buildConnection(1);
statement = buildStatement(connection);
statement = buildStatement(connection, false);

statement.begin();

Expand Down Expand Up @@ -313,4 +316,224 @@ public static void run() {

};

private static class P2PModeWriteTest {

private static class P2PNodeWriter implements Runnable {

private final byte[] executionIdBytes;
private final int id;

P2PNodeWriter(byte[] executionIdBytes, int id) {
this.executionIdBytes = executionIdBytes;
this.id = id;
}

@Override
public void run() {
ObDirectLoadConnection connection = null;
ObDirectLoadStatement statement = null;
try {
ObDirectLoadStatementExecutionId executionId = new ObDirectLoadStatementExecutionId();
executionId.decode(executionIdBytes);

connection = buildConnection(1);
statement = buildStatement(connection, executionId, true);

ObDirectLoadBucket bucket = new ObDirectLoadBucket();
ObObj[] rowObjs = new ObObj[2];
rowObjs[0] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), id);
rowObjs[1] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), id);
bucket.addRow(rowObjs);
statement.write(bucket);

} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != statement) {
statement.close();
}
if (null != connection) {
connection.close();
}
}
}

};

public static void run() {
System.out.println("P2PModeWriteTest start");
final int writeThreadNum = 10;
ObDirectLoadConnection connection = null;
ObDirectLoadStatement statement = null;
try {
prepareTestTable();

connection = buildConnection(1);
statement = buildStatement(connection, true);

statement.begin();

ObDirectLoadStatementExecutionId executionId = statement.getExecutionId();
byte[] executionIdBytes = executionId.encode();

Thread[] threads = new Thread[writeThreadNum];
for (int i = 0; i < threads.length; ++i) {
P2PNodeWriter NodeWriter = new P2PNodeWriter(executionIdBytes, i);
Thread thread = new Thread(NodeWriter);
thread.start();
threads[i] = thread;
}
for (int i = 0; i < threads.length; ++i) {
threads[i].join();
}

statement.commit();

queryTestTable(writeThreadNum);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != statement) {
statement.close();
}
if (null != connection) {
connection.close();
}
}
System.out.println("P2PModeWriteTest successful");
}

};

private static class SimpleAbortTest {

public static void run() {
System.out.println("SimpleAbortTest start");
ObDirectLoadConnection connection = null;
ObDirectLoadStatement statement = null;
try {
prepareTestTable();
System.out.println("prepareTestTable");

connection = buildConnection(1);
statement = buildStatement(connection, false);

statement.begin();

ObDirectLoadBucket bucket = new ObDirectLoadBucket();
ObObj[] rowObjs = new ObObj[2];
rowObjs[0] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), 1);
rowObjs[1] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), 2);
bucket.addRow(rowObjs);
statement.write(bucket);

statement.abort();

queryTestTable(0);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != statement) {
statement.close();
}
if (null != connection) {
connection.close();
}
}
System.out.println("SimpleAbortTest successful");
}

};

private static class P2PModeAbortTest {


private static class AbortP2PNode implements Runnable {

private final byte[] executionIdBytes;
private final int id;

AbortP2PNode(byte[] executionIdBytes, int id) {
this.executionIdBytes = executionIdBytes;
this.id = id;
}

@Override
public void run() {
ObDirectLoadConnection connection = null;
ObDirectLoadStatement statement = null;
try {
ObDirectLoadStatementExecutionId executionId = new ObDirectLoadStatementExecutionId();
executionId.decode(executionIdBytes);

connection = buildConnection(1);
statement = buildStatement(connection, executionId, true);

ObDirectLoadBucket bucket = new ObDirectLoadBucket();
ObObj[] rowObjs = new ObObj[2];
rowObjs[0] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), id);
rowObjs[1] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), id);
bucket.addRow(rowObjs);
statement.write(bucket);

statement.abort();

} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != statement) {
statement.close();
}
if (null != connection) {
connection.close();
}
}
}

};

public static void run() {
System.out.println("P2PModeAbortTest start");
ObDirectLoadConnection connection = null;
ObDirectLoadStatement statement = null;
try {
prepareTestTable();

connection = buildConnection(1);
statement = buildStatement(connection, true);

statement.begin();

ObDirectLoadBucket bucket = new ObDirectLoadBucket();
ObObj[] rowObjs = new ObObj[2];
rowObjs[0] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), 1);
rowObjs[1] = new ObObj(ObObjType.ObInt32Type.getDefaultObjMeta(), 2);
bucket.addRow(rowObjs);
statement.write(bucket);

ObDirectLoadStatementExecutionId executionId = statement.getExecutionId();
byte[] executionIdBytes = executionId.encode();

AbortP2PNode abortP2PNode = new AbortP2PNode(executionIdBytes, 3);
Thread abortNodeThread = new Thread(abortP2PNode);
abortNodeThread.start();
abortNodeThread.join();

queryTestTable(0);

} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != statement) {
statement.close();
}
if (null != connection) {
connection.close();
}
}
System.out.println("P2PModeAbortTest successful");
}

};

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public synchronized void init(Builder builder) throws ObDirectLoadException {
connection.getProtocol().checkIsSupported(this);
obTablePool = new ObDirectLoadConnection.ObTablePool(connection, logger, queryTimeout);
obTablePool.init();
executor = new ObDirectLoadStatementExecutor(this);
executor = new ObDirectLoadStatementExecutor(this, builder.isP2PMode);
if (builder.executionId != null) {
executor.resume(builder.executionId);
}
Expand Down Expand Up @@ -308,6 +308,10 @@ public void resume(ObDirectLoadStatementExecutionId executionId) throws ObDirect
executor.resume(executionId);
}

public void abort() throws ObDirectLoadException {
executor.requestAbort();
}

public static final class Builder {

private final ObDirectLoadConnection connection;
Expand All @@ -325,6 +329,7 @@ public static final class Builder {

private ObDirectLoadTraceId traceId = null;
private ObDirectLoadStatementExecutionId executionId = null;
private boolean isP2PMode = false;

private static final long MAX_QUERY_TIMEOUT = Integer.MAX_VALUE;

Expand Down Expand Up @@ -382,6 +387,11 @@ public ObDirectLoadTraceId getTraceId() {
return traceId;
}

public Builder setIsP2PMode(boolean isP2PMode) {
this.isP2PMode = isP2PMode;
return this;
}

public String toString() {
return String
.format(
Expand Down
Loading