MergeOp: Record the change set
We want to record a unique identifier which can be queried later to obtain all changes which were submitted together. Change-Id: I5ba29aa52c5dc20b37f3b7965a026fd6e84b814b Signed-off-by: Stefan Beller <sbeller@google.com>
This commit is contained in:
@@ -453,6 +453,13 @@ public final class Change {
|
|||||||
@Column(id = 17, notNull = false)
|
@Column(id = 17, notNull = false)
|
||||||
protected String originalSubject;
|
protected String originalSubject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique id for the changes submitted together assigned during merging.
|
||||||
|
* Only set if the status is MERGED.
|
||||||
|
*/
|
||||||
|
@Column(id = 18, notNull = false)
|
||||||
|
protected String submissionId;
|
||||||
|
|
||||||
protected Change() {
|
protected Change() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,6 +486,7 @@ public final class Change {
|
|||||||
currentPatchSetId = other.currentPatchSetId;
|
currentPatchSetId = other.currentPatchSetId;
|
||||||
subject = other.subject;
|
subject = other.subject;
|
||||||
originalSubject = other.originalSubject;
|
originalSubject = other.originalSubject;
|
||||||
|
submissionId = other.submissionId;
|
||||||
topic = other.topic;
|
topic = other.topic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,6 +570,14 @@ public final class Change {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSubmissionId() {
|
||||||
|
return submissionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubmissionId(String id) {
|
||||||
|
this.submissionId = id;
|
||||||
|
}
|
||||||
|
|
||||||
public Status getStatus() {
|
public Status getStatus() {
|
||||||
return Status.forCode(status);
|
return Status.forCode(status);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import com.google.common.collect.ListMultimap;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Table;
|
import com.google.common.collect.Table;
|
||||||
|
import com.google.common.hash.Hasher;
|
||||||
|
import com.google.common.hash.Hashing;
|
||||||
import com.google.gerrit.common.ChangeHooks;
|
import com.google.gerrit.common.ChangeHooks;
|
||||||
import com.google.gerrit.common.TimeUtil;
|
import com.google.gerrit.common.TimeUtil;
|
||||||
import com.google.gerrit.common.data.SubmitRecord;
|
import com.google.gerrit.common.data.SubmitRecord;
|
||||||
@@ -91,6 +93,8 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -143,7 +147,19 @@ public class MergeOp {
|
|||||||
|
|
||||||
private final Map<Change.Id, List<SubmitRecord>> records;
|
private final Map<Change.Id, List<SubmitRecord>> records;
|
||||||
private final Map<Change.Id, CodeReviewCommit> commits;
|
private final Map<Change.Id, CodeReviewCommit> commits;
|
||||||
private String logPrefix;
|
|
||||||
|
private static final String MACHINE_ID;
|
||||||
|
static {
|
||||||
|
String id;
|
||||||
|
try {
|
||||||
|
id = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
id = "unknown";
|
||||||
|
}
|
||||||
|
MACHINE_ID = id;
|
||||||
|
}
|
||||||
|
private String staticSubmissionId;
|
||||||
|
private String submissionId;
|
||||||
|
|
||||||
private ProjectState destProject;
|
private ProjectState destProject;
|
||||||
private ReviewDb db;
|
private ReviewDb db;
|
||||||
@@ -336,10 +352,19 @@ public class MergeOp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSubmissionId(Change change) {
|
||||||
|
Hasher h = Hashing.sha1().newHasher();
|
||||||
|
h.putLong(Thread.currentThread().getId())
|
||||||
|
.putUnencodedChars(MACHINE_ID);
|
||||||
|
staticSubmissionId = h.hash().toString().substring(0, 8);
|
||||||
|
submissionId = change.getId().get() + "-" + TimeUtil.nowMs() +
|
||||||
|
"-" + staticSubmissionId;
|
||||||
|
}
|
||||||
|
|
||||||
public void merge(ReviewDb db, Change change, IdentifiedUser caller,
|
public void merge(ReviewDb db, Change change, IdentifiedUser caller,
|
||||||
boolean checkSubmitRules) throws NoSuchChangeException,
|
boolean checkSubmitRules) throws NoSuchChangeException,
|
||||||
OrmException, ResourceConflictException {
|
OrmException, ResourceConflictException {
|
||||||
logPrefix = String.format("[%s]: ", String.valueOf(change.hashCode()));
|
updateSubmissionId(change);
|
||||||
this.db = db;
|
this.db = db;
|
||||||
logDebug("Beginning integration of {}", change);
|
logDebug("Beginning integration of {}", change);
|
||||||
try {
|
try {
|
||||||
@@ -997,6 +1022,7 @@ public class MergeOp {
|
|||||||
@Override
|
@Override
|
||||||
public Change update(Change c) {
|
public Change update(Change c) {
|
||||||
c.setStatus(Change.Status.MERGED);
|
c.setStatus(Change.Status.MERGED);
|
||||||
|
c.setSubmissionId(submissionId);
|
||||||
if (!merged.equals(c.currentPatchSetId())) {
|
if (!merged.equals(c.currentPatchSetId())) {
|
||||||
// Uncool; the patch set changed after we merged it.
|
// Uncool; the patch set changed after we merged it.
|
||||||
// Go back to the patch set that was actually merged.
|
// Go back to the patch set that was actually merged.
|
||||||
@@ -1253,28 +1279,28 @@ public class MergeOp {
|
|||||||
|
|
||||||
private void logDebug(String msg, Object... args) {
|
private void logDebug(String msg, Object... args) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(logPrefix + msg, args);
|
log.debug("[" + submissionId + "]" + msg, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logWarn(String msg, Throwable t) {
|
private void logWarn(String msg, Throwable t) {
|
||||||
if (log.isWarnEnabled()) {
|
if (log.isWarnEnabled()) {
|
||||||
log.warn(logPrefix + msg, t);
|
log.warn("[" + submissionId + "]" + msg, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logWarn(String msg) {
|
private void logWarn(String msg) {
|
||||||
if (log.isWarnEnabled()) {
|
if (log.isWarnEnabled()) {
|
||||||
log.warn(logPrefix + msg);
|
log.warn("[" + submissionId + "]" + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logError(String msg, Throwable t) {
|
private void logError(String msg, Throwable t) {
|
||||||
if (log.isErrorEnabled()) {
|
if (log.isErrorEnabled()) {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
log.error(logPrefix + msg, t);
|
log.error("[" + submissionId + "]" + msg, t);
|
||||||
} else {
|
} else {
|
||||||
log.error(logPrefix + msg);
|
log.error("[" + submissionId + "]" + msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import java.util.List;
|
|||||||
/** A version of the database schema. */
|
/** A version of the database schema. */
|
||||||
public abstract class SchemaVersion {
|
public abstract class SchemaVersion {
|
||||||
/** The current schema version. */
|
/** The current schema version. */
|
||||||
public static final Class<Schema_111> C = Schema_111.class;
|
public static final Class<Schema_112> C = Schema_112.class;
|
||||||
|
|
||||||
public static int getBinaryVersion() {
|
public static int getBinaryVersion() {
|
||||||
return guessVersion(C);
|
return guessVersion(C);
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// Copyright (C) 2015 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.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gwtorm.jdbc.JdbcSchema;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class Schema_112 extends SchemaVersion {
|
||||||
|
@Inject
|
||||||
|
Schema_112(Provider<Schema_111> prior) {
|
||||||
|
super(prior);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user