Files
gerrit/java/com/google/gerrit/server/index/OnlineReindexMode.java
Luca Milanesio 4dde1ff7e9 Online index upgrade: skip submit rules for closed changes
When upgrading an old changes index, it's not useful running
the submit rules on them for three reasons:

1. Gerrit setups may have millions of closed changes: running
   the submit rules again on them may take hours or days.

2. Closed changes would typically not be submittable at all,
   because they do not allow any submit operation.

3. Abandoned changes may be submittable when resumed, however
   the resume operation will re-compute the submit rule anyway
   so there is no value in evaluating them upfront.

Calculating submit rules for an ancient closed change can even
cause exceptions (e.g., target branch disappeared or removed)
and cause the failure of the changes index online migration.

By defining a thread-local flag when the online reindex is in
progress, the submit rule evaluator can "short-circuit" the
evaluation and return the closed record instead.

Bug: Issue 11148
Change-Id: I58674aa68d5a58d6f7e41773fe5d52ab3bb44acb
2019-07-09 23:56:20 +00:00

34 lines
1.0 KiB
Java

// Copyright (C) 2019 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.index;
import java.util.Optional;
public class OnlineReindexMode {
private static ThreadLocal<Boolean> isOnlineReindex = new ThreadLocal<>();
public static boolean isActive() {
return Optional.ofNullable(isOnlineReindex.get()).orElse(Boolean.FALSE);
}
public static void begin() {
isOnlineReindex.set(Boolean.TRUE);
}
public static void end() {
isOnlineReindex.set(Boolean.FALSE);
}
}