You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ta...@apache.org on 2021/06/29 03:11:35 UTC

[iotdb] branch enable_cache_leader created (now bd2d839)

This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a change to branch enable_cache_leader
in repository https://gitbox.apache.org/repos/asf/iotdb.git.


      at bd2d839  enable cache leader

This branch includes the following new commits:

     new bd2d839  enable cache leader

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


[iotdb] 01/01: enable cache leader

Posted by ta...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a commit to branch enable_cache_leader
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit bd2d839031356d3e2df8b72ec1cbda7068f39ede
Author: LebronAl <TX...@gmail.com>
AuthorDate: Tue Jun 29 11:11:02 2021 +0800

    enable cache leader
---
 .../src/main/java/org/apache/iotdb/session/Config.java |  2 +-
 .../main/java/org/apache/iotdb/session/Session.java    | 18 ++++++++++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/session/src/main/java/org/apache/iotdb/session/Config.java b/session/src/main/java/org/apache/iotdb/session/Config.java
index 4114594..02e7e70 100644
--- a/session/src/main/java/org/apache/iotdb/session/Config.java
+++ b/session/src/main/java/org/apache/iotdb/session/Config.java
@@ -24,7 +24,7 @@ public class Config {
   public static final String DEFAULT_PASSWORD = "root";
   public static final int DEFAULT_FETCH_SIZE = 5000;
   public static final int DEFAULT_CONNECTION_TIMEOUT_MS = 0;
-  public static final boolean DEFAULT_CACHE_LEADER_MODE = false;
+  public static final boolean DEFAULT_CACHE_LEADER_MODE = true;
 
   public static final int RETRY_NUM = 3;
   public static final long RETRY_INTERVAL_MS = 1000;
diff --git a/session/src/main/java/org/apache/iotdb/session/Session.java b/session/src/main/java/org/apache/iotdb/session/Session.java
index 447c2b5..ca32cfc 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -679,7 +679,9 @@ public class Session {
 
   private SessionConnection getSessionConnection(String deviceId) {
     EndPoint endPoint;
-    if (enableCacheLeader && (endPoint = deviceIdToEndpoint.get(deviceId)) != null) {
+    if (enableCacheLeader
+        && deviceIdToEndpoint.size() != 0
+        && (endPoint = deviceIdToEndpoint.get(deviceId)) != null) {
       return endPointToSessionConnection.get(endPoint);
     } else {
       return defaultSessionConnection;
@@ -898,7 +900,7 @@ public class Session {
     EndPoint endPoint;
     SessionConnection connection;
     for (int i = 0; i < deviceIds.size(); i++) {
-      endPoint = deviceIdToEndpoint.get(deviceIds.get(i));
+      endPoint = deviceIdToEndpoint.size() == 0 ? null : deviceIdToEndpoint.get(deviceIds.get(i));
       if (endPoint != null) {
         connection = endPointToSessionConnection.get(endPoint);
       } else {
@@ -1120,7 +1122,7 @@ public class Session {
     EndPoint endPoint;
     SessionConnection connection;
     for (int i = 0; i < deviceIds.size(); i++) {
-      endPoint = deviceIdToEndpoint.get(deviceIds.get(i));
+      endPoint = deviceIdToEndpoint.size() == 0 ? null : deviceIdToEndpoint.get(deviceIds.get(i));
       if (endPoint != null) {
         connection = endPointToSessionConnection.get(endPoint);
       } else {
@@ -1205,7 +1207,9 @@ public class Session {
     TSInsertTabletReq request = genTSInsertTabletReq(tablet, false);
     EndPoint endPoint;
     try {
-      if (enableCacheLeader && (endPoint = deviceIdToEndpoint.get(tablet.prefixPath)) != null) {
+      if (enableCacheLeader
+          && deviceIdToEndpoint.size() != 0
+          && (endPoint = deviceIdToEndpoint.get(tablet.prefixPath)) != null) {
         endPointToSessionConnection.get(endPoint).insertTablet(request);
       } else {
         defaultSessionConnection.insertTablet(request);
@@ -1226,7 +1230,9 @@ public class Session {
     TSInsertTabletReq request = genTSInsertTabletReq(tablet, sorted);
     EndPoint endPoint;
     try {
-      if (enableCacheLeader && (endPoint = deviceIdToEndpoint.get(tablet.prefixPath)) != null) {
+      if (enableCacheLeader
+          && deviceIdToEndpoint.size() != 0
+          && (endPoint = deviceIdToEndpoint.get(tablet.prefixPath)) != null) {
         endPointToSessionConnection.get(endPoint).insertTablet(request);
       } else {
         defaultSessionConnection.insertTablet(request);
@@ -1313,7 +1319,7 @@ public class Session {
     SessionConnection connection;
     Map<SessionConnection, TSInsertTabletsReq> tabletGroup = new HashMap<>();
     for (Entry<String, Tablet> entry : tablets.entrySet()) {
-      endPoint = deviceIdToEndpoint.get(entry.getKey());
+      endPoint = deviceIdToEndpoint.size() == 0 ? null : deviceIdToEndpoint.get(entry.getKey());
       if (endPoint != null) {
         connection = endPointToSessionConnection.get(endPoint);
       } else {