[branch-2.1] Picks "[fix](autoinc) Fix AutoIncrementGenerator and add more logs about auto-increment column #37306" (#37366)
## Proposed changes picks https://github.com/apache/doris/pull/37306
This commit is contained in:
@ -38,7 +38,6 @@ import java.io.IOException;
|
||||
public class AutoIncrementGenerator implements Writable, GsonPostProcessable {
|
||||
private static final Logger LOG = LogManager.getLogger(AutoIncrementGenerator.class);
|
||||
|
||||
public static final long NEXT_ID_INIT_VALUE = 1;
|
||||
// _MIN_BATCH_SIZE = 4064 in load task
|
||||
private static final long BATCH_ID_INTERVAL = 500000;
|
||||
|
||||
@ -62,6 +61,7 @@ public class AutoIncrementGenerator implements Writable, GsonPostProcessable {
|
||||
this.tableId = tableId;
|
||||
this.columnId = columnId;
|
||||
this.nextId = nextId;
|
||||
this.batchEndId = -1;
|
||||
}
|
||||
|
||||
public void setEditLog(EditLog editLog) {
|
||||
@ -70,6 +70,8 @@ public class AutoIncrementGenerator implements Writable, GsonPostProcessable {
|
||||
|
||||
public synchronized void applyChange(long columnId, long batchNextId) {
|
||||
if (this.columnId == columnId && batchEndId < batchNextId) {
|
||||
LOG.info("[auto-inc] AutoIncrementGenerator applyChange, db_id={}, table_id={}, column_id={}, "
|
||||
+ "batchNextId={}", dbId, tableId, columnId, batchNextId);
|
||||
nextId = batchNextId;
|
||||
batchEndId = batchNextId;
|
||||
}
|
||||
@ -77,20 +79,25 @@ public class AutoIncrementGenerator implements Writable, GsonPostProcessable {
|
||||
|
||||
public synchronized Pair<Long, Long> getAutoIncrementRange(long columnId,
|
||||
long length, long lowerBound) throws UserException {
|
||||
LOG.info("[getAutoIncrementRange request][col:{}][length:{}], [{}]", columnId, length, this.columnId);
|
||||
LOG.info("[auto-inc] getAutoIncrementRange request, db_id={}, table_id={}, column_id={}, length={}", dbId,
|
||||
tableId, columnId, length);
|
||||
if (this.columnId != columnId) {
|
||||
throw new UserException("column dosen't exist, columnId=" + columnId);
|
||||
}
|
||||
long startId = Math.max(nextId, lowerBound);
|
||||
long startId = nextId;
|
||||
long endId = startId + length;
|
||||
nextId = startId + length;
|
||||
if (endId > batchEndId) {
|
||||
Preconditions.checkState(editLog != null);
|
||||
AutoIncrementIdUpdateLog info = new AutoIncrementIdUpdateLog(dbId, tableId, columnId, batchEndId);
|
||||
long newBatchEndId = (endId / BATCH_ID_INTERVAL + 1) * BATCH_ID_INTERVAL;
|
||||
AutoIncrementIdUpdateLog info = new AutoIncrementIdUpdateLog(dbId, tableId, columnId, newBatchEndId);
|
||||
editLog.logUpdateAutoIncrementId(info);
|
||||
batchEndId = (endId / BATCH_ID_INTERVAL + 1) * BATCH_ID_INTERVAL;
|
||||
batchEndId = newBatchEndId;
|
||||
LOG.info("[auto-inc] update batchEndId to {}, db_id={}, table_id={}, column_id={}",
|
||||
newBatchEndId, dbId, tableId, columnId);
|
||||
}
|
||||
LOG.info("[getAutoIncrementRange result][{}, {}]", startId, length);
|
||||
nextId = endId;
|
||||
LOG.info("[auto-inc] getAutoIncrementRange result, db_id={}, table_id={}, column_id={}, start={}, length:{}",
|
||||
dbId, tableId, columnId, startId, length);
|
||||
return Pair.of(startId, length);
|
||||
}
|
||||
|
||||
@ -100,12 +107,16 @@ public class AutoIncrementGenerator implements Writable, GsonPostProcessable {
|
||||
}
|
||||
|
||||
public static AutoIncrementGenerator read(DataInput in) throws IOException {
|
||||
return GsonUtils.GSON.fromJson(Text.readString(in), AutoIncrementGenerator.class);
|
||||
AutoIncrementGenerator res = GsonUtils.GSON.fromJson(Text.readString(in), AutoIncrementGenerator.class);
|
||||
LOG.info("[auto-inc] read AutoIncrementGenerator db_id={}, table_id={}, column_id={}, nextId={}, "
|
||||
+ "batchEndId={}", res.dbId, res.tableId, res.columnId, res.nextId, res.batchEndId);
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gsonPostProcess() throws IOException {
|
||||
nextId = batchEndId;
|
||||
LOG.info("[auto-inc] AutoIncrementGenerator set nextId to batchEndId={}", batchEndId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2767,9 +2767,7 @@ public class FrontendServiceImpl implements FrontendService.Iface {
|
||||
@Override
|
||||
public TAutoIncrementRangeResult getAutoIncrementRange(TAutoIncrementRangeRequest request) {
|
||||
String clientAddr = getClientAddrAsString();
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("receive get auto-increement range request: {}, backend: {}", request, clientAddr);
|
||||
}
|
||||
LOG.info("[auto-inc] receive getAutoIncrementRange request: {}, backend: {}", request, clientAddr);
|
||||
|
||||
TAutoIncrementRangeResult result = new TAutoIncrementRangeResult();
|
||||
TStatus status = new TStatus(TStatusCode.OK);
|
||||
@ -2779,7 +2777,7 @@ public class FrontendServiceImpl implements FrontendService.Iface {
|
||||
status.setStatusCode(TStatusCode.NOT_MASTER);
|
||||
status.addToErrorMsgs(NOT_MASTER_ERR_MSG);
|
||||
result.setMasterAddress(getMasterAddress());
|
||||
LOG.error("failed to getAutoIncrementRange:{}, request:{}, backend:{}",
|
||||
LOG.error("[auto-inc] failed to getAutoIncrementRange:{}, request:{}, backend:{}",
|
||||
NOT_MASTER_ERR_MSG, request, getClientAddrAsString());
|
||||
return result;
|
||||
}
|
||||
@ -2792,19 +2790,16 @@ public class FrontendServiceImpl implements FrontendService.Iface {
|
||||
autoIncrementGenerator = olapTable.getAutoIncrementGenerator();
|
||||
long columnId = request.getColumnId();
|
||||
long length = request.getLength();
|
||||
long lowerBound = -1;
|
||||
if (request.isSetLowerBound()) {
|
||||
lowerBound = request.getLowerBound();
|
||||
}
|
||||
Pair<Long, Long> range = autoIncrementGenerator.getAutoIncrementRange(columnId, length, lowerBound);
|
||||
Pair<Long, Long> range = autoIncrementGenerator.getAutoIncrementRange(columnId, length, -1);
|
||||
result.setStart(range.first);
|
||||
result.setLength(range.second);
|
||||
} catch (UserException e) {
|
||||
LOG.warn("failed to get auto-increment range of column {}: {}", request.getColumnId(), e.getMessage());
|
||||
LOG.warn("[auto-inc] failed to get auto-increment range of db_id={}, table_id={}, column_id={}, errmsg={}",
|
||||
request.getDbId(), request.getTableId(), request.getColumnId(), e.getMessage());
|
||||
status.setStatusCode(TStatusCode.ANALYSIS_ERROR);
|
||||
status.addToErrorMsgs(e.getMessage());
|
||||
} catch (Throwable e) {
|
||||
LOG.warn("catch unknown result.", e);
|
||||
LOG.warn("[auto-inc] catch unknown result.", e);
|
||||
status.setStatusCode(TStatusCode.INTERNAL_ERROR);
|
||||
status.addToErrorMsgs(e.getClass().getSimpleName() + ": " + Strings.nullToEmpty(e.getMessage()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user