-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement broadcast distributing downstream
rename existing distributing downstream to ModuloDistributingDownstream
- Loading branch information
Showing
8 changed files
with
425 additions
and
63 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...rc/main/java/io/crate/executor/transport/distributed/BroadcastDistributingDownstream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to CRATE.IO GmbH ("Crate") under one or more contributor | ||
* license agreements. See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. Crate licenses | ||
* this file to you 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. | ||
* | ||
* However, if you have executed another commercial license agreement | ||
* with Crate these terms will supersede the license and you may use the | ||
* software solely pursuant to the terms of the relevant commercial agreement. | ||
*/ | ||
|
||
package io.crate.executor.transport.distributed; | ||
|
||
import io.crate.Constants; | ||
import io.crate.Streamer; | ||
import io.crate.core.collections.Bucket; | ||
import io.crate.core.collections.Row; | ||
import org.elasticsearch.common.logging.ESLogger; | ||
import org.elasticsearch.common.logging.Loggers; | ||
|
||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
public class BroadcastDistributingDownstream extends DistributingDownstream { | ||
|
||
private static final ESLogger LOGGER = Loggers.getLogger(BroadcastDistributingDownstream.class); | ||
|
||
private final SingleBucketBuilder bucketBuilder; | ||
|
||
public BroadcastDistributingDownstream(UUID jobId, | ||
int targetExecutionNodeId, | ||
int bucketIdx, | ||
Collection<String> downstreamNodeIds, | ||
TransportDistributedResultAction transportDistributedResultAction, | ||
Streamer<?>[] streamers) { | ||
super(jobId, targetExecutionNodeId, bucketIdx, downstreamNodeIds, transportDistributedResultAction, streamers); | ||
|
||
bucketBuilder = new SingleBucketBuilder(streamers); | ||
} | ||
|
||
@Override | ||
public boolean setNextRow(Row row) { | ||
if (allDownstreamsFinished()) { | ||
return false; | ||
} | ||
try { | ||
bucketBuilder.setNextRow(row); | ||
sendRequestsIfNeeded(); | ||
} catch (Exception e) { | ||
fail(e); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void sendRequestsIfNeeded() { | ||
int size = bucketBuilder.size(); | ||
if (size >= Constants.PAGE_SIZE || remainingUpstreams.get() <= 0) { | ||
Bucket bucket = bucketBuilder.build(); | ||
for (Downstream downstream : downstreams) { | ||
if (downstream.wantMore.get()) { | ||
downstream.bucketQueue.add(bucket); | ||
downstream.sendRequest(remainingUpstreams.get() <= 0); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onAllUpstreamsFinished() { | ||
sendRequestsIfNeeded(); | ||
} | ||
|
||
@Override | ||
protected ESLogger logger() { | ||
return LOGGER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
sql/src/main/java/io/crate/executor/transport/distributed/ModuloDistributingDownstream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Licensed to CRATE.IO GmbH ("Crate") under one or more contributor | ||
* license agreements. See the NOTICE file distributed with this work for | ||
* additional information regarding copyright ownership. Crate licenses | ||
* this file to you 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. | ||
* | ||
* However, if you have executed another commercial license agreement | ||
* with Crate these terms will supersede the license and you may use the | ||
* software solely pursuant to the terms of the relevant commercial agreement. | ||
*/ | ||
|
||
package io.crate.executor.transport.distributed; | ||
|
||
import io.crate.Constants; | ||
import io.crate.Streamer; | ||
import io.crate.core.collections.Row; | ||
import org.elasticsearch.common.logging.ESLogger; | ||
import org.elasticsearch.common.logging.Loggers; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
public class ModuloDistributingDownstream extends DistributingDownstream { | ||
|
||
private static final ESLogger LOGGER = Loggers.getLogger(ModuloDistributingDownstream.class); | ||
|
||
private final MultiBucketBuilder bucketBuilder; | ||
|
||
public ModuloDistributingDownstream(UUID jobId, | ||
int targetExecutionNodeId, | ||
int bucketIdx, | ||
Collection<String> downstreamNodeIds, | ||
TransportDistributedResultAction transportDistributedResultAction, | ||
Streamer<?>[] streamers) { | ||
super(jobId, targetExecutionNodeId, bucketIdx, downstreamNodeIds, transportDistributedResultAction, streamers); | ||
|
||
bucketBuilder = new MultiBucketBuilder(streamers, downstreams.length); | ||
} | ||
|
||
@Override | ||
public boolean setNextRow(Row row) { | ||
if (allDownstreamsFinished()) { | ||
return false; | ||
} | ||
try { | ||
int downstreamIdx = bucketBuilder.getBucket(row); | ||
// only collect if downstream want more rows, otherwise just ignore the row | ||
if (downstreams[downstreamIdx].wantMore.get()) { | ||
bucketBuilder.setNextRow(downstreamIdx, row); | ||
sendRequestIfNeeded(downstreamIdx); | ||
} | ||
} catch (IOException e) { | ||
fail(e); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void sendRequestIfNeeded(int downstreamIdx) { | ||
int size = bucketBuilder.size(downstreamIdx); | ||
if (size >= Constants.PAGE_SIZE || remainingUpstreams.get() <= 0) { | ||
Downstream downstream = downstreams[downstreamIdx]; | ||
downstream.bucketQueue.add(bucketBuilder.build(downstreamIdx)); | ||
downstream.sendRequest(remainingUpstreams.get() <= 0); | ||
} | ||
} | ||
|
||
protected void onAllUpstreamsFinished() { | ||
for (int i = 0; i < downstreams.length; i++) { | ||
sendRequestIfNeeded(i); | ||
} | ||
} | ||
protected ESLogger logger() { | ||
return LOGGER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.