Search in sources :

Example 6 with Location

use of io.dingodb.meta.Location in project dingo by dingodb.

the class JobRunner method distributeTasks.

/**
 * Distribute the tasks.
 *
 * @return the root task
 */
private Task distributeTasks() {
    Task rootTask = null;
    for (Task task : job.getTasks()) {
        if (task.getRoot() != null) {
            rootTask = task;
            continue;
        }
        Location location = task.getLocation();
        if (!location.equals(Services.META.currentLocation())) {
            try {
                Channel channel = Services.openNewSysChannel(location.getHost(), location.getPort());
                Message msg = SimpleMessage.builder().tag(SimpleTag.TASK_TAG).content(task.serialize()).build();
                channel.send(msg);
                channel.close();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("Error to distribute tasks.", e);
            }
        }
    }
    assert rootTask != null : "There must be one and only one root task.";
    return rootTask;
}
Also used : Task(io.dingodb.exec.base.Task) Message(io.dingodb.net.Message) SimpleMessage(io.dingodb.net.SimpleMessage) Channel(io.dingodb.net.Channel) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Location(io.dingodb.meta.Location)

Example 7 with Location

use of io.dingodb.meta.Location in project dingo by dingodb.

the class PartitionOperator method createOutputs.

public void createOutputs(String tableName, @Nonnull Map<String, Location> partLocations) {
    outputs = new HashMap<>(partLocations.size());
    for (Map.Entry<String, Location> partLocation : partLocations.entrySet()) {
        OutputHint hint = OutputHint.of(tableName, partLocation.getKey());
        hint.setLocation(partLocation.getValue());
        Output output = OutputIml.of(this);
        output.setHint(hint);
        outputs.put(partLocation.getKey(), output);
    }
}
Also used : OutputHint(io.dingodb.exec.base.OutputHint) Output(io.dingodb.exec.base.Output) HashMap(java.util.HashMap) Map(java.util.Map) Location(io.dingodb.meta.Location)

Example 8 with Location

use of io.dingodb.meta.Location in project dingo by dingodb.

the class MetaTestService method createTable.

@Override
public void createTable(@Nonnull String tableName, @Nonnull TableDefinition tableDefinition) {
    try {
        OutputStream os = new FileOutputStream(metaFile(tableName));
        tableDefinition.writeJson(os);
        // force reload
        tableDefinitionMap = null;
        Map<String, Location> partLocations = getPartLocations(tableName);
        for (Map.Entry<String, Location> entry : partLocations.entrySet()) {
            StoreInstance store = Services.KV_STORE.getInstance(entry.getValue().getPath());
            new PartInKvStore(store.getKvBlock(new TableId(getTableKey(tableName)), entry.getKey()), tableDefinition.getTupleSchema(), tableDefinition.getKeyMapping());
        }
    } catch (IOException e) {
        log.error("Failed to write table definition: {}", tableDefinition);
        throw new AssertionError("Failed to write table definition.");
    }
}
Also used : TableId(io.dingodb.common.table.TableId) PartInKvStore(io.dingodb.exec.table.PartInKvStore) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StoreInstance(io.dingodb.store.api.StoreInstance) Location(io.dingodb.meta.Location)

Example 9 with Location

use of io.dingodb.meta.Location in project dingo by dingodb.

the class TableMetaAdaptorImpl method rangeLocationGroup.

@Override
public NavigableMap<byte[], LocationGroup> rangeLocationGroup() {
    NavigableMap<byte[], LocationGroup> result = new TreeMap<>(BytesUtil.getDefaultByteArrayComparator());
    Map<GeneralId, AppView<?, ?>> map = this.scheduleMetaAdaptor.namespaceView().appViews();
    for (Map.Entry<GeneralId, AppView<?, ?>> entry : map.entrySet()) {
        if (entry.getValue() instanceof RegionView) {
            RegionView view = (RegionView) entry.getValue();
            ExecutorView executorView = this.scheduleMetaAdaptor.executorView(view.leader());
            Endpoint endpoint = executorView.stats().getLocation();
            Location location = new Location(endpoint.getIp(), endpoint.getPort(), DATA_DIR);
            List<Location> locationList = view.nodeResources().stream().map(id -> this.scheduleMetaAdaptor.namespaceView().<ExecutorView>getResourceView(id)).map(ExecutorView::location).collect(Collectors.toList());
            LocationGroup locationGroup = new LocationGroup(location, locationList);
            RegionApp regionApp = this.scheduleMetaAdaptor.regionApp(view.app());
            result.put(BytesUtil.nullToEmpty(regionApp.startKey()), locationGroup);
        }
    }
    return result;
}
Also used : AppView(io.dingodb.server.coordinator.app.AppView) ExecutorView(io.dingodb.server.coordinator.resource.impl.ExecutorView) TreeMap(java.util.TreeMap) RegionApp(io.dingodb.server.coordinator.app.impl.RegionApp) GeneralId(io.dingodb.server.coordinator.GeneralId) Endpoint(io.dingodb.raft.util.Endpoint) RegionView(io.dingodb.server.coordinator.app.impl.RegionView) LocationGroup(io.dingodb.meta.LocationGroup) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Location(io.dingodb.meta.Location)

Aggregations

Location (io.dingodb.meta.Location)9 Output (io.dingodb.exec.base.Output)6 Task (io.dingodb.exec.base.Task)6 Map (java.util.Map)6 TableDefinition (io.dingodb.common.table.TableDefinition)4 TableId (io.dingodb.common.table.TableId)4 LinkedList (java.util.LinkedList)4 PartitionStrategy (io.dingodb.exec.partition.PartitionStrategy)3 SimpleHashStrategy (io.dingodb.exec.partition.SimpleHashStrategy)3 ArrayList (java.util.ArrayList)3 OutputHint (io.dingodb.exec.base.OutputHint)2 List (java.util.List)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TupleSchema (io.dingodb.common.table.TupleSchema)1 Id (io.dingodb.exec.base.Id)1 GetByKeysOperator (io.dingodb.exec.operator.GetByKeysOperator)1 PartScanOperator (io.dingodb.exec.operator.PartScanOperator)1 PartitionOperator (io.dingodb.exec.operator.PartitionOperator)1 ReceiveOperator (io.dingodb.exec.operator.ReceiveOperator)1