3636import java .util .concurrent .BlockingQueue ;
3737import java .util .concurrent .ConcurrentHashMap ;
3838import java .util .concurrent .LinkedBlockingQueue ;
39- import java .util .concurrent .TimeUnit ;
4039import java .util .concurrent .atomic .AtomicBoolean ;
4140
4241/**
@@ -77,28 +76,20 @@ public SplitAssignment(
7776 public void init () throws UserException {
7877 splitGenerator .startSplit (backendPolicy .numBackends ());
7978 synchronized (assignLock ) {
80- final int waitIntervalTimeMillis = 100 ;
81- final int initTimeoutMillis = 30000 ; // 30s
82- int waitTotalTime = 0 ;
83- while (sampleSplit == null && needMoreSplit ()) {
79+ while (sampleSplit == null && waitFirstSplit ()) {
8480 try {
85- assignLock .wait (waitIntervalTimeMillis );
81+ assignLock .wait (100 );
8682 } catch (InterruptedException e ) {
8783 throw new UserException (e .getMessage (), e );
8884 }
89- waitTotalTime += waitIntervalTimeMillis ;
90- if (waitTotalTime > initTimeoutMillis ) {
91- throw new UserException ("Failed to get first split after waiting for "
92- + (waitTotalTime / 1000 ) + " seconds." );
93- }
9485 }
9586 }
9687 if (exception != null ) {
9788 throw exception ;
9889 }
9990 }
10091
101- public boolean needMoreSplit () {
92+ private boolean waitFirstSplit () {
10293 return !scheduleFinished .get () && !isStopped .get () && exception == null ;
10394 }
10495
@@ -109,16 +100,10 @@ private void appendBatch(Multimap<Backend, Split> batch) throws UserException {
109100 for (Split split : splits ) {
110101 locations .add (splitToScanRange .getScanRange (backend , locationProperties , split , pathPartitionKeys ));
111102 }
112- while (needMoreSplit ()) {
113- BlockingQueue <Collection <TScanRangeLocations >> queue =
114- assignment .computeIfAbsent (backend , be -> new LinkedBlockingQueue <>(10000 ));
115- try {
116- if (queue .offer (locations , 100 , TimeUnit .MILLISECONDS )) {
117- return ;
118- }
119- } catch (InterruptedException e ) {
120- addUserException (new UserException ("Failed to offer batch split by interrupted" , e ));
121- }
103+ try {
104+ assignment .computeIfAbsent (backend , be -> new LinkedBlockingQueue <>(10000 )).put (locations );
105+ } catch (Exception e ) {
106+ throw new UserException ("Failed to offer batch split" , e );
122107 }
123108 }
124109 }
@@ -135,7 +120,7 @@ public Split getSampleSplit() {
135120 return sampleSplit ;
136121 }
137122
138- public void addToQueue (List <Split > splits ) throws UserException {
123+ public void addToQueue (List <Split > splits ) {
139124 if (splits .isEmpty ()) {
140125 return ;
141126 }
@@ -145,9 +130,19 @@ public void addToQueue(List<Split> splits) throws UserException {
145130 sampleSplit = splits .get (0 );
146131 assignLock .notify ();
147132 }
148- batch = backendPolicy .computeScanRangeAssignment (splits );
133+ try {
134+ batch = backendPolicy .computeScanRangeAssignment (splits );
135+ } catch (UserException e ) {
136+ exception = e ;
137+ }
138+ }
139+ if (batch != null ) {
140+ try {
141+ appendBatch (batch );
142+ } catch (UserException e ) {
143+ exception = e ;
144+ }
149145 }
150- appendBatch (batch );
151146 }
152147
153148 private void notifyAssignment () {
@@ -169,18 +164,10 @@ public BlockingQueue<Collection<TScanRangeLocations>> getAssignedSplits(Backend
169164 }
170165
171166 public void setException (UserException e ) {
172- addUserException ( e ) ;
167+ exception = e ;
173168 notifyAssignment ();
174169 }
175170
176- private void addUserException (UserException e ) {
177- if (exception != null ) {
178- exception .addSuppressed (e );
179- } else {
180- exception = e ;
181- }
182- }
183-
184171 public void finishSchedule () {
185172 scheduleFinished .set (true );
186173 notifyAssignment ();
@@ -200,9 +187,6 @@ public void stop() {
200187 }
201188 });
202189 notifyAssignment ();
203- if (exception != null ) {
204- throw new RuntimeException (exception );
205- }
206190 }
207191
208192 public boolean isStop () {
0 commit comments