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:25:04 UTC

[iotdb] branch enable_cache_leader_0.12 created (now 2b87ace)

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

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


      at 2b87ace  enable cache leader

This branch includes the following new commits:

     new 2b87ace  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_0.12
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 2b87acef0266e8dc74825b350e6ca77d46a52952
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 e517161..432855c 100644
--- a/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -592,7 +592,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;
@@ -794,7 +796,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 {
@@ -1016,7 +1018,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 {
@@ -1101,7 +1103,9 @@ public class Session {
     TSInsertTabletReq request = genTSInsertTabletReq(tablet, false);
     EndPoint endPoint;
     try {
-      if (enableCacheLeader && (endPoint = deviceIdToEndpoint.get(tablet.deviceId)) != null) {
+      if (enableCacheLeader
+          && deviceIdToEndpoint.size() != 0
+          && (endPoint = deviceIdToEndpoint.get(tablet.deviceId)) != null) {
         endPointToSessionConnection.get(endPoint).insertTablet(request);
       } else {
         defaultSessionConnection.insertTablet(request);
@@ -1122,7 +1126,9 @@ public class Session {
     TSInsertTabletReq request = genTSInsertTabletReq(tablet, sorted);
     EndPoint endPoint;
     try {
-      if (enableCacheLeader && (endPoint = deviceIdToEndpoint.get(tablet.deviceId)) != null) {
+      if (enableCacheLeader
+          && deviceIdToEndpoint.size() != 0
+          && (endPoint = deviceIdToEndpoint.get(tablet.deviceId)) != null) {
         endPointToSessionConnection.get(endPoint).insertTablet(request);
       } else {
         defaultSessionConnection.insertTablet(request);
@@ -1192,7 +1198,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 {