forked from trinodb/trino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
159 additions
and
57 deletions.
There are no files selected for viewing
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
...rino/plugin/adb/connector/protocol/gpfdist/load/process/GpfdistPageProcessorProvider.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 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. | ||
*/ | ||
package io.trino.plugin.adb.connector.protocol.gpfdist.load.process; | ||
|
||
import io.trino.plugin.adb.connector.protocol.gpfdist.load.PageProcessor; | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.locks.Condition; | ||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class GpfdistPageProcessorProvider | ||
implements PageProcessorProvider | ||
{ | ||
private static final long ADB_SEGMENT_WAIT_TIMEOUT = 60000L; | ||
private final ConcurrentLinkedQueue<PageProcessor> pageProcessors = new ConcurrentLinkedQueue<>(); | ||
private final AtomicBoolean isReadyForProcessing = new AtomicBoolean(false); | ||
private final ReentrantLock lock = new ReentrantLock(); | ||
private final Condition isReadyForProcessingCondition = lock.newCondition(); | ||
|
||
public GpfdistPageProcessorProvider() | ||
{ | ||
} | ||
|
||
@Override | ||
public void add(PageProcessor processor) | ||
{ | ||
lock.lock(); | ||
try { | ||
pageProcessors.add(processor); | ||
isReadyForProcessing.set(true); | ||
isReadyForProcessingCondition.signalAll(); | ||
} | ||
finally { | ||
lock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public PageProcessor take() | ||
{ | ||
lock.lock(); | ||
try { | ||
if (!isReadyForProcessing.get()) { | ||
long startTime = System.currentTimeMillis(); | ||
while (pageProcessors.isEmpty()) { | ||
try { | ||
if (System.currentTimeMillis() - startTime > ADB_SEGMENT_WAIT_TIMEOUT) { | ||
throw new RuntimeException( | ||
format("Timeout :%d ms waiting for segments responses is exceeded", | ||
ADB_SEGMENT_WAIT_TIMEOUT)); | ||
} | ||
isReadyForProcessingCondition.await(); | ||
} | ||
catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
PageProcessor pageProcessor = pageProcessors.poll(); | ||
pageProcessors.offer(pageProcessor); | ||
return pageProcessor; | ||
} | ||
finally { | ||
lock.unlock(); | ||
} | ||
} | ||
|
||
@Override | ||
public ConcurrentLinkedQueue<PageProcessor> getAll() | ||
{ | ||
return pageProcessors; | ||
} | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
...va/io/trino/plugin/adb/connector/protocol/gpfdist/load/process/PageProcessorProvider.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,27 @@ | ||
/* | ||
* Licensed 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. | ||
*/ | ||
package io.trino.plugin.adb.connector.protocol.gpfdist.load.process; | ||
|
||
import io.trino.plugin.adb.connector.protocol.gpfdist.load.PageProcessor; | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
public interface PageProcessorProvider | ||
{ | ||
void add(PageProcessor processor); | ||
|
||
PageProcessor take(); | ||
|
||
ConcurrentLinkedQueue<PageProcessor> getAll(); | ||
} |
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