Skip to content

Commit c9e99cd

Browse files
committed
[fix][dingo-exec] SortOperator spillToDisk
1 parent 84db568 commit c9e99cd

13 files changed

Lines changed: 753 additions & 79 deletions

File tree

dingo-calcite/src/main/java/io/dingodb/calcite/visitor/function/DingoSortVisitFun.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package io.dingodb.calcite.visitor.function;
1818

1919
import io.dingodb.calcite.rel.dingo.DingoSort;
20+
import io.dingodb.calcite.type.converter.DefinitionMapper;
2021
import io.dingodb.calcite.visitor.DingoJobVisitor;
2122
import io.dingodb.common.ExecutionContext;
2223
import io.dingodb.common.Location;
2324
import io.dingodb.common.table.HybridSearchTable;
25+
import io.dingodb.common.type.DingoType;
2426
import io.dingodb.exec.base.IdGenerator;
2527
import io.dingodb.exec.base.Job;
2628
import io.dingodb.exec.dag.Vertex;
@@ -62,12 +64,13 @@ static class OperatorSupplier implements Supplier<Vertex> {
6264

6365
@Override
6466
public Vertex get() {
67+
DingoType schema = DefinitionMapper.mapToDingoType(rel.getInput().getRowType());
6568
SortParam param = new SortParam(
6669
toSortCollation(rel.getCollation().getFieldCollations()),
6770
rel.fetch == null ? -1 : RexLiteral.intValue(rel.fetch),
6871
rel.offset == null ? 0 : RexLiteral.intValue(rel.offset),
6972
rel.getHints().stream().anyMatch( e -> e.hintName.equalsIgnoreCase(HybridSearchTable.HINT_NAME)),
70-
executionContext);
73+
executionContext, schema, 0);
7174
return new Vertex(SORT, param);
7275
}
7376
}

dingo-common/src/main/java/io/dingodb/common/config/DingoConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public class DingoConfiguration {
5454
private SecurityConfiguration security = new SecurityConfiguration();
5555
private VariableConfiguration variable = new VariableConfiguration();
5656
private CommonConfiguration common = new CommonConfiguration();
57+
private SpillConfiguration spill = new SpillConfiguration();
5758

5859
public static synchronized void parse(final String configPath) throws Exception {
5960
if (configPath != null) {
@@ -63,6 +64,7 @@ public static synchronized void parse(final String configPath) throws Exception
6364
INSTANCE.security = INSTANCE.getConfig("security", SecurityConfiguration.class);
6465
INSTANCE.variable = INSTANCE.getConfig("variable", VariableConfiguration.class);
6566
INSTANCE.common = INSTANCE.getConfig("common", CommonConfiguration.class);
67+
INSTANCE.spill = INSTANCE.getConfig("spill", SpillConfiguration.class);
6668
}
6769

6870
private static void copyConfig(Map<String, Object> from, Map<String, Object> to) {
@@ -117,6 +119,15 @@ public static Integer lowerCaseTableNames() {
117119
return Optional.mapOrGet(INSTANCE.variable, VariableConfiguration::getLowerCaseTableNames, () -> 2);
118120
}
119121

122+
public static String spillDir() {
123+
return Optional.mapOrGet(INSTANCE.spill, SpillConfiguration::getDir,
124+
() -> System.getProperty("java.io.tmpdir") + java.io.File.separator + "dingo-spill");
125+
}
126+
127+
public static int spillThreshold() {
128+
return Optional.mapOrGet(INSTANCE.spill, SpillConfiguration::getThreshold, () -> 100000);
129+
}
130+
120131
public static CommonId serverId() {
121132
return INSTANCE.serverId;
122133
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.common.config;
18+
19+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
20+
import lombok.Getter;
21+
import lombok.Setter;
22+
import lombok.ToString;
23+
24+
import java.io.File;
25+
26+
@Getter
27+
@Setter
28+
@ToString
29+
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
30+
public class SpillConfiguration {
31+
private String dir = System.getProperty("java.io.tmpdir") + File.separator + "dingo-spill";
32+
33+
private Integer threshold = 100000;
34+
}

dingo-exec/src/main/java/io/dingodb/exec/codec/AvroTupleCodec.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,22 @@ record = decodeBytes(is, record, reader);
107107
}
108108
return tuples;
109109
}
110+
111+
public @Nullable Object[] decodeOne(@NonNull BinaryDecoder decoder) throws IOException {
112+
GenericRecord record;
113+
try {
114+
record = reader.read(null, decoder);
115+
} catch (EOFException e) {
116+
return null;
117+
}
118+
if (record == null) {
119+
return null;
120+
}
121+
int size = schema.getFields().size();
122+
Object[] tuple = new Object[size];
123+
for (int i = 0; i < size; ++i) {
124+
tuple[i] = record.get(i);
125+
}
126+
return (Object[]) type.convertFrom(tuple, AvroDataConverter.INSTANCE);
127+
}
110128
}

dingo-exec/src/main/java/io/dingodb/exec/dag/Edge.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public boolean transformToNext(Context context, Object[] tuple) {
7575
try {
7676
blocked.get();
7777
//checkExecutorFinishedRevoking((MemoryRevoker) operator, blocked, next.getData());
78-
LogUtils.info(log, "memory revoke locked continue..");
7978
break;
8079
} catch (InterruptedException | ExecutionException e) {
8180
throw new RuntimeException(e);
@@ -116,7 +115,7 @@ public ListenableFuture<?> handleMemoryRevoke(AbstractParams param, Operator ope
116115
ListenableFuture<?> future = memoryRevoker.startMemoryRevoke(param);
117116
if (future != null) {
118117
RevokerParams revokerParams = (RevokerParams) param;
119-
LogUtils.info(log, "async memory revoke, poolName:{}, pre pin:{}, param cnt:{}",
118+
LogUtils.debug(log, "async memory revoke, poolName:{}, pre pin:{}, param cnt:{}",
120119
memoryAllocatorCtx.getName(), previous.getPin(), revokerParams.getCacheSize());
121120
}
122121
return future;

dingo-exec/src/main/java/io/dingodb/exec/memory/OperatorMemoryAllocatorCtx.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public synchronized void resetMemoryRevokingRequested() {
141141
return;
142142
}
143143
memoryRevokingRequestedFuture = SettableFuture.create();
144-
LogUtils.info(log, "resetMemoryRevokingRequested");
144+
LogUtils.debug(log, "resetMemoryRevokingRequested");
145145
}
146146

147147
@Override
@@ -231,7 +231,7 @@ public synchronized long requestMemoryRevokingOrReturnRevokingBytes(long revokeF
231231
checkState(revocable, "requestMemoryRevoking for unRevocable operator");
232232
boolean alreadyRequested = isMemoryRevokingRequested();
233233
if (!alreadyRequested && revocableAllocated.get() > 0) {
234-
LogUtils.info(log, "request memory revoking,name:{}, revocableAllocated:{}, revokeFlag:{}",
234+
LogUtils.debug(log, "request memory revoking,name:{}, revocableAllocated:{}, revokeFlag:{}",
235235
this.getName(), revocableAllocated.get(), revokeFlag);
236236
memoryRevokingRequestedFuture.set(null);
237237
return revocableAllocated.get();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.exec.memory;
18+
19+
import java.util.concurrent.ConcurrentHashMap;
20+
21+
public class RocksdbSpiller implements Spiller {
22+
23+
@Override
24+
public void spill(ConcurrentHashMap hashMap) {
25+
// manager rocksdb instance
26+
// loop map
27+
// encode key: jobId + opId + unique_id + TupleKey + inc
28+
// encode val: TupleWithJoinFlag
29+
// write to rocksdb
30+
}
31+
32+
@Override
33+
public void close() {
34+
35+
}
36+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.exec.memory;
18+
19+
import java.util.concurrent.ConcurrentHashMap;
20+
21+
public interface Spiller {
22+
void spill(ConcurrentHashMap hashMap);
23+
24+
void close();
25+
}

0 commit comments

Comments
 (0)