Skip to content
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

WIP: Fetch list of nodes in a cluster client #129

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b424720
refactor
pda4code Feb 4, 2019
e5d2015
Method refreshServerList "created"
Feb 5, 2019
397c090
Create a TarantoolNode that describes a node
Feb 8, 2019
653d4de
Implementing ClusterTopologyDiscoverer.java & co
pda4code Feb 10, 2019
3bde207
Add test benchmark
pda4code Feb 11, 2019
c38304b
Implement non-working tarantool client impl read-write measurment
Feb 12, 2019
c0839e8
Attempt to refactor
Feb 13, 2019
bd9276b
Yet another attempt to force the benchmark to work
Feb 14, 2019
de2e9ef
Yet another refactor iteration
pda4code Feb 17, 2019
848fcf2
Refactor reading from channel
pda4code Feb 24, 2019
2239322
AbstractTarantoolConnectorIT restore RESTART_TIMEOUT value
pda4code Feb 24, 2019
10854fc
SelectorChannelReadHelper fix + add some todo
pda4code Feb 24, 2019
2b02862
Move connection logic to channel provider. Part1
Feb 25, 2019
4918ba4
Works onRoundRobinSocketChannelProvider; Some refactors
pda4code Feb 25, 2019
a8dde82
Try replace socket provider with NodeCommunicationProvider.
Feb 26, 2019
20b2eb0
Make connector compilable
pda4code Feb 26, 2019
7379be8
Implementing TarantoolClusterClient#refreshServerList method
Feb 27, 2019
9bf51b7
Make connector compilable
pda4code Feb 28, 2019
8ddadda
Try to resolve race-conditions at readFromInstance and refreshServerList
pda4code Mar 4, 2019
4aa0852
Upgrade refreshServerList method: stop IO before process old connection
Mar 4, 2019
57cbc7c
IMplement cleaning futuresSentToOldConnection collection
pda4code Mar 5, 2019
3a32574
Pass Async/Sync tarantool client test. Cleanup code from todos and
pda4code Mar 6, 2019
7d7bafd
Write a test for cluster topology discoverer. Fix the discoverer inte…
pda4code Mar 10, 2019
6e98d22
Rename: SingleNodeCommunicationProvider -> SingleNodeConnectionProvider
pda4code Mar 10, 2019
bb69dd8
Rename: NodeCommunicationProvider -> InstanceConnectionProvider
pda4code Mar 10, 2019
65db6ab
Rename: TestNodeConnectionProvider -> TestInstanceConnectionProvider;…
pda4code Mar 10, 2019
db8e2e2
jdbc: remove the outdated tarantool sql types
nicktorwald Mar 11, 2019
2520b59
fix broken tests
nicktorwald Mar 13, 2019
df19295
Move readPacket method into TarantoolInstanceConnection
pda4code Mar 14, 2019
85b8994
add a todo
pda4code Mar 14, 2019
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
73 changes: 72 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
<artifactId>connector</artifactId>
<version>1.9.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.3.1</junit.jupiter.version>

<jmh.version>1.21</jmh.version>
<maven-assembly-plugin.version>2.6</maven-assembly-plugin.version>
</properties>

<name>Tarantool Connector for Java</name>
<url>https://github.com/tarantool/tarantool-java</url>
<description>Tarantool client for java</description>
Expand Down Expand Up @@ -40,11 +45,28 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<version>3.6.1</version> <!--incresed from 3.2 due to lack of annotation processing support-->
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is more appropriate for a commit message.

<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>

<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
<!--
Set parsedVersion.majorVersion and parsedVersion.minorVersion
Expand All @@ -61,6 +83,18 @@
<goal>parse-version</goal>
</goals>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/perf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- Process src/main/java-templates directory. -->
Expand Down Expand Up @@ -124,6 +158,31 @@
</dependency>
</dependencies>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptor>src/main/assembly/perf-tests.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<archive>
<manifest>
<mainClass>org.openjdk.jmh.Main</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand All @@ -134,6 +193,12 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
Expand All @@ -146,6 +211,12 @@
<version>1.23</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<parent>
Expand Down
45 changes: 13 additions & 32 deletions src/it/java/org/tarantool/TestTarantoolClient.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.tarantool;

import org.tarantool.server.TarantoolBinaryPacket;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -33,8 +33,8 @@ public static class TarantoolClientTestImpl extends TarantoolClientImpl {
final Semaphore s = new Semaphore(0);
long latency = 1L;

public TarantoolClientTestImpl(SocketChannelProvider socketProvider, TarantoolClientConfig options) {
super(socketProvider, options);
public TarantoolClientTestImpl(InstanceConnectionProvider nodeComm, TarantoolClientConfig options) {
super(nodeComm, options);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -55,16 +55,6 @@ public void run() {
t.start();
}

@Override
protected void writeFully(SocketChannel channel, ByteBuffer buffer) throws IOException {
try {
Thread.sleep(1L);
} catch (InterruptedException e) {
e.printStackTrace();
}
super.writeFully(channel, buffer);
}

@Override
protected void configureThreads(String threadName) {
super.configureThreads(threadName);
Expand All @@ -81,14 +71,14 @@ protected void reconnect(int retry, Throwable lastError) {
}

@Override
protected void complete(long code, CompletableFuture<?> q) {
super.complete(code, q);
protected void complete(TarantoolBinaryPacket pack, CompletableFuture<?> q) {
super.complete(pack, q);
Long code = pack.getCode();
if (code != 0) {
System.out.println(code);
}
s.release();
}

}

public static void main(String[] args) throws IOException, InterruptedException, ExecutionException, SQLException {
Expand All @@ -102,21 +92,12 @@ public static void main(String[] args) throws IOException, InterruptedException,
config.sharedBufferSize = 128;

//config.sharedBufferSize = 0;
SocketChannelProvider socketChannelProvider = new SocketChannelProvider() {
@Override
public SocketChannel get(int retryNumber, Throwable lastError) {
if (lastError != null) {
lastError.printStackTrace(System.out);
}
System.out.println("reconnect");
try {
return SocketChannel.open(new InetSocketAddress("localhost", 3301));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
};
final TarantoolClientTestImpl client = new TarantoolClientTestImpl(socketChannelProvider, config);

InstanceConnectionProvider nodeComm =
new SingleInstanceConnectionProvider("localhost:3301", config.username, config.password);


final TarantoolClientTestImpl client = new TarantoolClientTestImpl(nodeComm, config);
config.writeTimeoutMillis = 2;
client.latency = 1;
client.syncOps.ping();
Expand Down
28 changes: 28 additions & 0 deletions src/main/assembly/perf-tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>perf-tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why /? Maybe target or testroot is better?

<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question here: why /?

<includes>
<include>**/*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
4 changes: 2 additions & 2 deletions src/main/java-templates/org/tarantool/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public final class Version {
public static final String version = "${project.version}";
public static final int majorVersion = ${parsedVersion.majorVersion};
public static final int minorVersion = ${parsedVersion.minorVersion};
public static final int majorVersion = Integer.parseInt("${parsedVersion.majorVersion}");
public static final int minorVersion = Integer.parseInt("${parsedVersion.minorVersion}");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't add this file into sources manually. IDEA find a generated file when the project is added as maven project. Please, revert this hunk.

}
2 changes: 1 addition & 1 deletion src/main/java/org/tarantool/CountInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.io.InputStream;

public abstract class CountInputStream extends InputStream {
abstract long getBytesRead();
public abstract long getBytesRead();
}
13 changes: 13 additions & 0 deletions src/main/java/org/tarantool/InstanceConnectionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.tarantool;

import org.tarantool.server.*;

import java.io.*;
import java.nio.*;

public interface InstanceConnectionProvider {

TarantoolInstanceConnection connect() throws IOException;

String getDescription();
}
19 changes: 10 additions & 9 deletions src/main/java/org/tarantool/JDBCBridge.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package org.tarantool;

import org.tarantool.jdbc.SQLResultSet;
import org.tarantool.server.TarantoolBinaryPacket;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.tarantool.jdbc.SQLResultSet;

public class JDBCBridge {
public static final JDBCBridge EMPTY = new JDBCBridge(Collections.<TarantoolBase.SQLMetaData>emptyList(), Collections.<List<Object>>emptyList());

final List<TarantoolBase.SQLMetaData> sqlMetadata;
final Map<String,Integer> columnsByName;
final List<List<Object>> rows;

protected JDBCBridge(TarantoolConnection connection) {
this(connection.getSQLMetadata(),connection.getSQLData());
protected JDBCBridge(TarantoolBinaryPacket pack) {
this(SqlProtoUtils.getSQLMetadata(pack), SqlProtoUtils.getSQLData(pack));
}

protected JDBCBridge(List<TarantoolBase.SQLMetaData> sqlMetadata, List<List<Object>> rows) {
Expand All @@ -30,8 +31,8 @@ protected JDBCBridge(List<TarantoolBase.SQLMetaData> sqlMetadata, List<List<Obje
}

public static JDBCBridge query(TarantoolConnection connection, String sql, Object ... params) {
connection.sql(sql, params);
return new JDBCBridge(connection);
TarantoolBinaryPacket pack = connection.sql(sql, params);
return new JDBCBridge(pack);
}

public static int update(TarantoolConnection connection, String sql, Object ... params) {
Expand All @@ -47,10 +48,10 @@ public static JDBCBridge mock(List<String> fields, List<List<Object>> values) {
}

public static Object execute(TarantoolConnection connection, String sql, Object ... params) {
connection.sql(sql, params);
Long rowCount = connection.getSqlRowCount();
TarantoolBinaryPacket pack = connection.sql(sql, params);
Long rowCount = SqlProtoUtils.getSqlRowCount(pack);
if(rowCount == null) {
return new SQLResultSet(new JDBCBridge(connection));
return new SQLResultSet(new JDBCBridge(pack));
}
return rowCount.intValue();
}
Expand Down
Loading