Replace ACCOUNT_DIFF_PREFERENCES table with Git backend (part1)

Replace the usage of AccountDiffPreference with a different class in
extension API package.

Data is saved optimized in Git backend: default values are discarded
during save operation and restored during read operation; so that
this optimization step is transparent for the callers.

For example when only one setting, theme in this case, differs from
the default value, only this value is written into diff section in
preferences.config file:

+[diff]
+       theme = eclipse

To support live migration, the upgrade is done in two steps:

* part1 (this change):
  o Always write to both git and db
  o Introduce new configuration option to indicate whether to read from
    git or db, initially set to read from db
  o First binary update: some servers are reading/writing just the db;
    some servers are additionally writing to git
  o After first update: all servers are reading from the db, writing to
    both
  o Batch copy data from db to git (only related to non open source
    Gerrit version)
  o Update all servers to read from git. During the update, some will
    still be reading from the db; that's ok, because everybody is
    writing to git
* part2 (next change):
  o Bump database version, migrate the data from db to git, delete the
    table (and the flag) from the code and update the servers.

Change-Id: I30a6d82f4a8d0c33ae9bb26d7f93c66bd0cb8bee
This commit is contained in:
David Ostrovsky
2014-11-16 18:48:50 +01:00
committed by Edwin Kempin
parent ddd8ec8d06
commit 7d5a771844
43 changed files with 836 additions and 475 deletions

View File

@@ -16,8 +16,8 @@ package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.common.auth.SignInRequired;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountProjectWatch;
import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.RemoteJsonService;
@@ -35,7 +35,7 @@ public interface AccountService extends RemoteJsonService {
@Audit
@SignInRequired
void changeDiffPreferences(AccountDiffPreference diffPref,
void changeDiffPreferences(DiffPreferencesInfo diffPref,
AsyncCallback<VoidResult> callback);
@SignInRequired

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.RemoteJsonService;
@@ -29,5 +29,5 @@ public interface ChangeDetailService extends RemoteJsonService {
@Audit
void patchSetDetail2(PatchSet.Id baseId, PatchSet.Id key,
AccountDiffPreference diffPrefs, AsyncCallback<PatchSetDetail> callback);
DiffPreferencesInfo diffPrefs, AsyncCallback<PatchSetDetail> callback);
}

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.common.data;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import java.util.Date;
import java.util.List;
@@ -22,7 +22,7 @@ import java.util.List;
/** Data sent as part of the host page, to bootstrap the UI. */
public class HostPageData {
public String version;
public AccountDiffPreference accountDiffPref;
public DiffPreferencesInfo accountDiffPref;
public String xGerritAuth;
public Theme theme;
public List<String> plugins;

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.common.data;
import com.google.gerrit.common.audit.Audit;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwtjsonrpc.common.AsyncCallback;
@@ -27,5 +27,5 @@ import com.google.gwtjsonrpc.common.RpcImpl.Version;
public interface PatchDetailService extends RemoteJsonService {
@Audit
void patchScript(Patch.Key key, PatchSet.Id a, PatchSet.Id b,
AccountDiffPreference diffPrefs, AsyncCallback<PatchScript> callback);
DiffPreferencesInfo diffPrefs, AsyncCallback<PatchScript> callback);
}

View File

@@ -14,10 +14,10 @@
package com.google.gerrit.common.data;
import com.google.gerrit.extensions.client.DiffPreferencesInfo;
import com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace;
import com.google.gerrit.prettify.common.EditList;
import com.google.gerrit.prettify.common.SparseFileContent;
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Patch;
import com.google.gerrit.reviewdb.client.Patch.ChangeType;
@@ -42,7 +42,7 @@ public class PatchScript {
protected FileMode oldMode;
protected FileMode newMode;
protected List<String> header;
protected AccountDiffPreference diffPrefs;
protected DiffPreferencesInfo diffPrefs;
protected SparseFileContent a;
protected SparseFileContent b;
protected List<Edit> edits;
@@ -62,7 +62,7 @@ public class PatchScript {
public PatchScript(final Change.Key ck, final ChangeType ct, final String on,
final String nn, final FileMode om, final FileMode nm,
final List<String> h, final AccountDiffPreference dp,
final List<String> h, final DiffPreferencesInfo dp,
final SparseFileContent ca, final SparseFileContent cb,
final List<Edit> e, final DisplayMethod ma, final DisplayMethod mb,
final String mta, final String mtb, final CommentDetail cd,
@@ -142,11 +142,11 @@ public class PatchScript {
return history;
}
public AccountDiffPreference getDiffPrefs() {
public DiffPreferencesInfo getDiffPrefs() {
return diffPrefs;
}
public void setDiffPrefs(AccountDiffPreference dp) {
public void setDiffPrefs(DiffPreferencesInfo dp) {
diffPrefs = dp;
}
@@ -155,7 +155,7 @@ public class PatchScript {
}
public boolean isIgnoreWhitespace() {
return diffPrefs.getIgnoreWhitespace() != Whitespace.IGNORE_NONE;
return diffPrefs.ignoreWhitespace != Whitespace.IGNORE_NONE;
}
public boolean hasIntralineDifference() {
@@ -171,7 +171,7 @@ public class PatchScript {
}
public boolean isExpandAllComments() {
return diffPrefs.isExpandAllComments();
return diffPrefs.expandAllComments;
}
public SparseFileContent getA() {
@@ -195,8 +195,8 @@ public class PatchScript {
}
public Iterable<EditList.Hunk> getHunks() {
int ctx = diffPrefs.getContext();
if (ctx == AccountDiffPreference.WHOLE_FILE_CONTEXT) {
int ctx = diffPrefs.context;
if (ctx == DiffPreferencesInfo.WHOLE_FILE_CONTEXT) {
ctx = Math.max(a.size(), b.size());
}
return new EditList(edits, ctx, a.size(), b.size()).getHunks();