Merge branch 'stable-3.6' into stable-3.7

* stable-3.6:
  Set version to 3.6.8-SNAPSHOT
  Set version to 3.6.7
  Update Eclipse dev guide
  Support Cloud Spanner for AccountPatchReviewStore
  Remove warning on persisted_projects cache on multi-servers setups
  Documentation: NOTE on use of sshkeys, and *projects cache on clusters
  Align Jetty session timeout with Gerrit web_sessions maxAge

Release-Notes: skip
Change-Id: I9e2c9aca2b14078e65fe529d76de09c770aa63f9
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt
index 2f4df9a..34d8933 100644
--- a/Documentation/config-gerrit.txt
+++ b/Documentation/config-gerrit.txt
@@ -37,9 +37,10 @@
 
 [[accountPatchReviewDb.url]]accountPatchReviewDb.url::
 +
-The url of accountPatchReviewDb. Supported types are `H2`, `POSTGRESQL`,
-`MARIADB`, and `MYSQL`. Drop the driver jar in the lib folder of the site path
-if the Jdbc driver of the corresponding Database is not yet in the class path.
+The url of accountPatchReviewDb. Supported types are `CLOUDSPANNER`, `H2`,
+`POSTGRESQL`, `MARIADB`, and `MYSQL`. Drop the driver jar in the lib folder of
+the site path if the Jdbc driver of the corresponding Database is not yet in
+the class path.
 +
 Default is to create H2 database in the db folder of the site path.
 +
@@ -1204,6 +1205,9 @@
 cache should be flushed.  Newly inserted projects do not require
 a cache flush, as they will be read upon first reference.
 
+NOTE: This cache should be disabled or set with a low refreshAfterWrite
+in a cluster setup using multiple primary or multiple replica nodes.
+
 cache `"prolog_rules"`::
 +
 Caches parsed `rules.pl` contents for each project. This cache uses the same
@@ -1230,6 +1234,9 @@
 As each individual user account may configure multiple SSH keys,
 the total number of keys may be larger than the item count.
 
+NOTE: This cache should be disabled or set with a low refreshAfterWrite
+in a cluster setup using multiple primary or multiple replica nodes.
+
 cache `"web_sessions"`::
 +
 Tracks the live user sessions coming in over HTTP.  Flushing this
@@ -1246,6 +1253,9 @@
 +
 Session storage is relatively inexpensive. The average entry in
 this cache is approximately 346 bytes.
++
+The `maxAge` configuration is also used for as maximum lifetime
+of the HTTP servlet container session.
 
 See also link:cmd-flush-caches.html[gerrit flush-caches].
 
diff --git a/Documentation/dev-eclipse.txt b/Documentation/dev-eclipse.txt
index 79febe4..4d68691 100644
--- a/Documentation/dev-eclipse.txt
+++ b/Documentation/dev-eclipse.txt
@@ -81,6 +81,10 @@
 link:dev-build-plugins.html#_bundle_custom_plugin_in_release_war[bundling in release.war]
 and run `tools/eclipse/project.py`.
 
+If a plugin requires additional test dependencies (not available in the Gerrit), then in order to
+execute tests directly from Eclipse, that plugin must be also added to `CUSTOM_PLUGINS_TEST_DEPS`
+list in `tools/bzl/plugins.bzl` (note that `tools/eclipse/project.py` has to be run again).
+
 == Java Versions
 
 Java 11 is supported as a default, but some adjustments must be done for other JDKs:
diff --git a/java/com/google/gerrit/pgm/http/jetty/JettyServer.java b/java/com/google/gerrit/pgm/http/jetty/JettyServer.java
index 6f3514f..10fe2f3 100644
--- a/java/com/google/gerrit/pgm/http/jetty/JettyServer.java
+++ b/java/com/google/gerrit/pgm/http/jetty/JettyServer.java
@@ -14,7 +14,9 @@
 
 package com.google.gerrit.pgm.http.jetty;
 
+import static com.google.gerrit.httpd.CacheBasedWebSession.MAX_AGE_MINUTES;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.MINUTES;
 import static java.util.concurrent.TimeUnit.SECONDS;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -244,6 +246,15 @@
           }
         });
 
+    sessionHandler.setMaxInactiveInterval(
+        (int)
+            cfg.getTimeUnit(
+                "cache",
+                "web_sessions",
+                "maxAge",
+                SECONDS.convert(MAX_AGE_MINUTES, MINUTES),
+                SECONDS));
+
     Handler app = makeContext(env, cfg, sessionHandler);
     if (cfg.getBoolean("httpd", "requestLog", !reverseProxy)) {
       RequestLogHandler handler = new RequestLogHandler();
diff --git a/java/com/google/gerrit/server/schema/CloudSpannerAccountPatchReviewStore.java b/java/com/google/gerrit/server/schema/CloudSpannerAccountPatchReviewStore.java
new file mode 100644
index 0000000..3c88e3a
--- /dev/null
+++ b/java/com/google/gerrit/server/schema/CloudSpannerAccountPatchReviewStore.java
@@ -0,0 +1,67 @@
+// Copyright (C) 2023 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gerrit.server.schema;
+
+import com.google.gerrit.exceptions.DuplicateKeyException;
+import com.google.gerrit.exceptions.StorageException;
+import com.google.gerrit.server.config.GerritServerConfig;
+import com.google.gerrit.server.config.SitePaths;
+import com.google.gerrit.server.config.ThreadSettingsConfig;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.sql.SQLException;
+import java.sql.Statement;
+import org.eclipse.jgit.lib.Config;
+
+@Singleton
+public class CloudSpannerAccountPatchReviewStore extends JdbcAccountPatchReviewStore {
+
+  private static final int ERR_DUP_KEY = 1022;
+  private static final int ERR_DUP_ENTRY = 1062;
+  private static final int ERR_DUP_UNIQUE = 1169;
+
+  @Inject
+  CloudSpannerAccountPatchReviewStore(
+      @GerritServerConfig Config cfg,
+      SitePaths sitePaths,
+      ThreadSettingsConfig threadSettingsConfig) {
+    super(cfg, sitePaths, threadSettingsConfig);
+  }
+
+  @Override
+  public StorageException convertError(String op, SQLException err) {
+    switch (err.getErrorCode()) {
+      case ERR_DUP_KEY:
+      case ERR_DUP_ENTRY:
+      case ERR_DUP_UNIQUE:
+        return new DuplicateKeyException("ACCOUNT_PATCH_REVIEWS", err);
+
+      default:
+        convertError(op, err);
+        return new StorageException(op + " failure on ACCOUNT_PATCH_REVIEWS", err);
+    }
+  }
+
+  @Override
+  protected void doCreateTable(Statement stmt) throws SQLException {
+    stmt.executeUpdate(
+        "CREATE TABLE IF NOT EXISTS account_patch_reviews ("
+            + "account_id INT64 NOT NULL DEFAULT (0),"
+            + "change_id INT64 NOT NULL DEFAULT (0),"
+            + "patch_set_id INT64 NOT NULL DEFAULT (0),"
+            + "file_name STRING(MAX) NOT NULL DEFAULT ('')"
+            + ") PRIMARY KEY(change_id, patch_set_id, account_id, file_name)");
+  }
+}
diff --git a/java/com/google/gerrit/server/schema/JdbcAccountPatchReviewStore.java b/java/com/google/gerrit/server/schema/JdbcAccountPatchReviewStore.java
index 189d448..8cc140e 100644
--- a/java/com/google/gerrit/server/schema/JdbcAccountPatchReviewStore.java
+++ b/java/com/google/gerrit/server/schema/JdbcAccountPatchReviewStore.java
@@ -53,8 +53,9 @@
     implements AccountPatchReviewStore, LifecycleListener {
   private static final FluentLogger logger = FluentLogger.forEnclosingClass();
 
-  // DB_CLOSE_DELAY=-1: By default the content of an in-memory H2 database is lost at the moment the
-  // last connection is closed. This option keeps the content as long as the VM lives.
+  // DB_CLOSE_DELAY=-1: By default the content of an in-memory H2 database is lost
+  // at the moment the last connection is closed. This option keeps the content as
+  // long as the VM lives.
   @VisibleForTesting
   public static final String TEST_IN_MEMORY_URL =
       "jdbc:h2:mem:account_patch_reviews;DB_CLOSE_DELAY=-1";
@@ -64,6 +65,7 @@
   private static final String MARIADB = "mariadb";
   private static final String MYSQL = "mysql";
   private static final String POSTGRESQL = "postgresql";
+  private static final String CLOUDSPANNER = "cloudspanner";
   private static final String URL = "url";
 
   public static class JdbcAccountPatchReviewStoreModule extends LifecycleModule {
@@ -85,6 +87,8 @@
         impl = MysqlAccountPatchReviewStore.class;
       } else if (url.contains(MARIADB)) {
         impl = MariaDBAccountPatchReviewStore.class;
+      } else if (url.contains(CLOUDSPANNER)) {
+        impl = CloudSpannerAccountPatchReviewStore.class;
       } else {
         throw new IllegalArgumentException(
             "unsupported driver type for account patch reviews db: " + url);
@@ -111,6 +115,9 @@
     if (url.contains(MARIADB)) {
       return new MariaDBAccountPatchReviewStore(cfg, sitePaths, threadSettingsConfig);
     }
+    if (url.contains(CLOUDSPANNER)) {
+      return new CloudSpannerAccountPatchReviewStore(cfg, sitePaths, threadSettingsConfig);
+    }
     throw new IllegalArgumentException(
         "unsupported driver type for account patch reviews db: " + url);
   }
@@ -164,6 +171,9 @@
     if (url.contains(MARIADB)) {
       return "org.mariadb.jdbc.Driver";
     }
+    if (url.contains(CLOUDSPANNER)) {
+      return "com.google.cloud.spanner.jdbc.JdbcDriver";
+    }
     return "org.h2.Driver";
   }