Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a2d961f

Browse filesBrowse files
committed
Report not only VirtualShardId but also "real" Id of datasource in case of error.
1 parent 7b298a8 commit a2d961f
Copy full SHA for a2d961f

File tree

Expand file treeCollapse file tree

7 files changed

+25
-12
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+25
-12
lines changed

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>de.zalando</groupId>
66
<artifactId>zalando-sprocwrapper</artifactId>
7-
<version>1.0.3</version>
7+
<version>1.0.4</version>
88
<packaging>jar</packaging>
99
<name>Stored Procedure Wrapper</name>
1010
<description>Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces including automatic object serialization and deserialization (using typemapper and convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types such as enums and hstore.</description>

‎src/main/java/de/zalando/sprocwrapper/dsprovider/ArrayDataSourceProvider.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/dsprovider/ArrayDataSourceProvider.java
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,26 @@
1010
* @author jmussler
1111
*/
1212
public class ArrayDataSourceProvider implements DataSourceProvider {
13-
private DataSource[] dss;
13+
private final DataSource[] dss;
1414

1515
public ArrayDataSourceProvider(final DataSource[] ds) {
1616
dss = ds;
1717
}
1818

1919
@Override
20-
public DataSource getDataSource(final int id) {
21-
return dss[id % dss.length];
20+
public int getDataSourceId(final int virtualShardId) {
21+
return virtualShardId % dss.length; //To change body of implemented methods use File | Settings | File Templates.
22+
}
23+
24+
@Override
25+
public DataSource getDataSource(final int virtualShardId) {
26+
return dss[virtualShardId % dss.length];
2227
}
2328

2429
@Override
2530
public List<Integer> getDistinctShardIds() {
26-
List<Integer> shardIds = Lists.newArrayListWithExpectedSize(dss.length);
31+
final List<Integer> shardIds = Lists.newArrayListWithExpectedSize(dss.length);
32+
2733
for (int i = 0; i < dss.length; i++) {
2834
shardIds.add(i);
2935
}

‎src/main/java/de/zalando/sprocwrapper/dsprovider/BitmapShardDataSourceProvider.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/dsprovider/BitmapShardDataSourceProvider.java
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,11 @@ public BitmapShardDataSourceProvider(final Class<? extends DataSource> dataSourc
141141

142142
}
143143

144-
/**
145-
* Letzten 3 Bit bestimmen 8 Shards.
146-
*/
144+
@Override
145+
public int getDataSourceId(final int virtualShardId) {
146+
return virtualShardId & mask;
147+
}
148+
147149
@Override
148150
public DataSource getDataSource(final int virtualShardId) {
149151
return dataSources[virtualShardId & mask];

‎src/main/java/de/zalando/sprocwrapper/dsprovider/DataSourceProvider.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/dsprovider/DataSourceProvider.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @author jmussler
99
*/
1010
public interface DataSourceProvider {
11+
int getDataSourceId(int virtualShardId);
1112
DataSource getDataSource(int virtualShardId);
12-
1313
List<Integer> getDistinctShardIds();
1414
}

‎src/main/java/de/zalando/sprocwrapper/dsprovider/SingleDataSourceProvider.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/dsprovider/SingleDataSourceProvider.java
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public SingleDataSourceProvider(final DataSource ds) {
1515
dataSource = ds;
1616
}
1717

18+
@Override
19+
public int getDataSourceId(int virtualShardId) {
20+
return 1;
21+
}
22+
1823
@Override
1924
public DataSource getDataSource(final int id) {
2025
return dataSource;

‎src/main/java/de/zalando/sprocwrapper/proxy/StoredProcedure.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/proxy/StoredProcedure.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ public Object execute(final DataSourceProvider dp, final Object[] args) {
433433
connection = firstDs.getConnection();
434434

435435
} catch (final SQLException e) {
436-
throw new CannotGetJdbcConnectionException("Failed to acquire connection for virtual shard "
437-
+ shardIds.get(0) + " for " + name, e);
436+
throw new CannotGetJdbcConnectionException("Failed to acquire connection for virtual shard " + shardIds.get(0)
437+
+ " translates to" + dp.getDataSourceId(shardIds.get(0)) + " for " + name, e);
438438
}
439439

440440
final List<Object[]> paramValues = Lists.newArrayList();

‎src/main/java/de/zalando/sprocwrapper/proxy/executors/ValidationExecutorWrapper.java

Copy file name to clipboardExpand all lines: src/main/java/de/zalando/sprocwrapper/proxy/executors/ValidationExecutorWrapper.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ValidationExecutorWrapper implements Executor {
3131
try {
3232
factory = Validation.buildDefaultValidatorFactory();
3333
} catch (final Exception e) {
34-
// ignore - we may not be able to initialize the factory.
34+
LOG.error("",e);
3535
}
3636
}
3737

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.