Skip to content

Commit eb79d50

Browse files
guojn1githubgxll
authored andcommitted
[fix][dingo-calcite] Modifying column names leads to data loss
1 parent 03c8f7f commit eb79d50

File tree

3 files changed

+7
-61
lines changed

3 files changed

+7
-61
lines changed

dingo-calcite/src/main/java/io/dingodb/calcite/DingoDdlExecutor.java

+3
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,9 @@ public static int getReplica(int targetReplica, int type) {
19981998

19991999
private static void validateAddColumn(ColumnDefinition newColumn) {
20002000
DingoType type = newColumn.getType();
2001+
if ("NULL".equalsIgnoreCase(newColumn.getDefaultValue())) {
2002+
newColumn.setDefaultValue(null);
2003+
}
20012004
if (newColumn.getDefaultValue() == null) {
20022005
if (!newColumn.isNullable()) {
20032006
if (type instanceof StringType) {

dingo-executor/src/main/java/io/dingodb/server/executor/ddl/IndexAddFiller.java

-61
Original file line numberDiff line numberDiff line change
@@ -362,17 +362,6 @@ public boolean commitSecond() {
362362
param.setPartId(newPartId);
363363
param.setTableId(tableId);
364364
}
365-
//String key = Base64.getEncoder().encodeToString(keyValue.getKey());
366-
//if (!caches.containsKey(key)) {
367-
// caches.put(key, keyValue);
368-
//}
369-
//if (caches.size() % max_pre_write_count == 0) {
370-
// try {
371-
// commitSecondData(caches.values());
372-
// } finally {
373-
// caches.clear();
374-
// }
375-
//}
376365
}
377366
if (!param.getKeys().isEmpty()) {
378367
boolean result = txnCommit(param, txnId, param.getTableId(), param.getPartId());
@@ -518,56 +507,6 @@ private Iterator<KeyValue> getLocalIterator() {
518507
return cache.scan(prefix);
519508
}
520509

521-
public void commitSecondData(Collection<KeyValue> secondData) {
522-
CommitParam param = new CommitParam(dingoType, isolationLevel, txnId.seq,
523-
commitTs, primaryKey, TransactionType.OPTIMISTIC);
524-
param.init(null);
525-
for (KeyValue keyValue : secondData) {
526-
CommonId tableId = indexTable.tableId;
527-
int from = 1;
528-
//Arrays.copyOfRange(keyValue.getKey(), from, from += CommonId.LEN);
529-
from += CommonId.LEN;
530-
CommonId newPartId = CommonId.decode(Arrays.copyOfRange(keyValue.getKey(), from, from += CommonId.LEN));
531-
byte[] key = new byte[keyValue.getKey().length - from];
532-
System.arraycopy(keyValue.getKey(), from , key, 0, key.length);
533-
CommonId partId = param.getPartId();
534-
if (partId == null) {
535-
partId = newPartId;
536-
param.setPartId(partId);
537-
param.setTableId(tableId);
538-
param.addKey(key);
539-
} else if (partId.equals(newPartId)) {
540-
param.addKey(key);
541-
if (param.getKeys().size() == max_pre_write_count) {
542-
boolean result = txnCommit(param, txnId, tableId, partId);
543-
if (!result) {
544-
throw new RuntimeException(txnId + " " + partId + ",txnCommit false,PrimaryKey:"
545-
+ Arrays.toString(param.getPrimaryKey()));
546-
}
547-
param.getKeys().clear();
548-
param.setPartId(null);
549-
}
550-
} else {
551-
boolean result = txnCommit(param, txnId, param.getTableId(), partId);
552-
if (!result) {
553-
throw new RuntimeException(txnId + " " + partId + ",txnCommit false,PrimaryKey:"
554-
+ Arrays.toString(param.getPrimaryKey()));
555-
}
556-
param.getKeys().clear();
557-
param.addKey(key);
558-
param.setPartId(newPartId);
559-
param.setTableId(tableId);
560-
}
561-
}
562-
if (!param.getKeys().isEmpty()) {
563-
boolean result = txnCommit(param, txnId, param.getTableId(), param.getPartId());
564-
if (!result) {
565-
throw new RuntimeException(txnId + " " + param.getPartId()
566-
+ ",txnCommit false,PrimaryKey:" + Arrays.toString(param.getPrimaryKey()));
567-
}
568-
}
569-
}
570-
571510
public TxnLocalData getTxnLocalData(Object[] tuplesTmp) {
572511
KeyValue keyValue = wrap(indexCodec::encode).apply(tuplesTmp);
573512
NavigableMap<ByteArrayUtils.ComparableByteArray, RangeDistribution> ranges =

dingo-executor/src/main/java/io/dingodb/server/executor/ddl/ModifyColumnFiller.java

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.Iterator;
4848
import java.util.NavigableMap;
4949
import java.util.stream.Collectors;
50+
import java.util.stream.IntStream;
5051

5152
import static io.dingodb.common.CommonId.CommonType.FILL_BACK;
5253
import static io.dingodb.common.util.NoBreakFunctions.wrap;
@@ -84,6 +85,9 @@ public boolean preWritePrimary(ReorgBackFillTask task) {
8485
columnIndices = table.getColumnIndices(indexTable.columns.stream()
8586
.map(Column::getName)
8687
.collect(Collectors.toList()));
88+
if (columnIndices.contains(-1)) {
89+
columnIndices = IntStream.range(0, table.getColumns().size()).boxed().collect(Collectors.toList());
90+
}
8791
colLen = columnIndices.size();
8892
indexCodec = CodecService.getDefault()
8993
.createKeyValueCodec(indexTable.getCodecVersion(), indexTable.version, indexTable.tupleType(),

0 commit comments

Comments
 (0)