3737import org .apache .iotdb .db .conf .IoTDBConfig ;
3838import org .apache .iotdb .db .conf .IoTDBDescriptor ;
3939import org .apache .iotdb .db .exception .LoadAnalyzeException ;
40+ import org .apache .iotdb .db .exception .LoadAnalyzeMissingSchemaException ;
4041import org .apache .iotdb .db .exception .LoadAnalyzeTypeMismatchException ;
4142import org .apache .iotdb .db .exception .load .LoadEmptyFileException ;
4243import org .apache .iotdb .db .exception .load .LoadFileException ;
@@ -214,6 +215,9 @@ public Analysis analyzeFileByFile(Analysis analysis) {
214215 // the real result on the conversion will be set in the analysis.
215216 return analysis ;
216217 } catch (Exception e ) {
218+ if (setTemporaryUnavailableStatusIfNecessary (analysis , e )) {
219+ return analysis ;
220+ }
217221 final String exceptionMessage =
218222 String .format (
219223 "Auto create or verify schema error when executing statement %s. Detail: %s." ,
@@ -315,6 +319,9 @@ private boolean doAnalyzeFileByFile(Analysis analysis) {
315319 "The file %s is not a valid tsfile. Please check the input file." ,
316320 tsFile .getPath ()));
317321 } catch (Exception e ) {
322+ if (setTemporaryUnavailableStatusIfNecessary (analysis , e )) {
323+ return false ;
324+ }
318325 final String exceptionMessage =
319326 String .format (
320327 "Loading file %s failed. Detail: %s" ,
@@ -484,6 +491,10 @@ private Analysis setFailAnalysisForAuthException(Analysis analysis, AuthExceptio
484491
485492 private Analysis executeTabletConversionOnException (
486493 final Analysis analysis , final LoadAnalyzeException e ) {
494+ if (setTemporaryUnavailableStatusIfNecessary (analysis , e )) {
495+ return analysis ;
496+ }
497+
487498 if (shouldSkipConversion (e )) {
488499 analysis .setFailStatus (
489500 new TSStatus (TSStatusCode .LOAD_FILE_ERROR .getStatusCode ()).setMessage (e .getMessage ()));
@@ -517,6 +528,52 @@ private Analysis executeTabletConversionOnException(
517528 return analysis ;
518529 }
519530
531+ private boolean setTemporaryUnavailableStatusIfNecessary (
532+ final Analysis analysis , final Throwable throwable ) {
533+ if (isTemporaryUnavailableDueToPipeSchemaNotReady (throwable )) {
534+ setFailAnalysisForTemporaryUnavailablePipeSchema (analysis , throwable );
535+ return true ;
536+ }
537+ if (isGeneratedByPipe && LoadTsFileDataTypeConverter .isMemoryPressureException (throwable )) {
538+ analysis .setFinishQueryAfterAnalyze (true );
539+ analysis .setFailStatus (LoadTsFileDataTypeConverter .getMemoryPressureStatus (throwable ));
540+ analysis .setStatement (loadTsFileStatement );
541+ return true ;
542+ }
543+ return false ;
544+ }
545+
546+ private void setFailAnalysisForTemporaryUnavailablePipeSchema (
547+ final Analysis analysis , final Throwable throwable ) {
548+ final String exceptionMessage =
549+ String .format (
550+ "Pipe generated LoadTsFile is waiting for schema metadata to be transferred. Detail: %s" ,
551+ throwable .getMessage () == null
552+ ? throwable .getClass ().getName ()
553+ : throwable .getMessage ());
554+ analysis .setFinishQueryAfterAnalyze (true );
555+ analysis .setFailStatus (
556+ RpcUtils .getStatus (TSStatusCode .LOAD_TEMPORARY_UNAVAILABLE_EXCEPTION , exceptionMessage ));
557+ analysis .setStatement (loadTsFileStatement );
558+ }
559+
560+ boolean isTemporaryUnavailableDueToPipeSchemaNotReady (final Throwable throwable ) {
561+ if (!isGeneratedByPipe
562+ || !isVerifySchema
563+ || IoTDBDescriptor .getInstance ().getConfig ().isAutoCreateSchemaEnabled ()) {
564+ return false ;
565+ }
566+
567+ Throwable current = throwable ;
568+ while (current != null ) {
569+ if (current instanceof LoadAnalyzeMissingSchemaException ) {
570+ return true ;
571+ }
572+ current = current .getCause ();
573+ }
574+ return false ;
575+ }
576+
520577 private boolean shouldSkipConversion (LoadAnalyzeException e ) {
521578 return (e instanceof LoadAnalyzeTypeMismatchException )
522579 && !loadTsFileStatement .isConvertOnTypeMismatch ();
@@ -545,7 +602,7 @@ public void setCurrentTimeIndex(final ITimeIndex timeIndex) {
545602 public void autoCreateAndVerify (
546603 TsFileSequenceReader reader ,
547604 Map <IDeviceID , List <TimeseriesMetadata >> device2TimeSeriesMetadataList )
548- throws IOException , AuthException , LoadAnalyzeTypeMismatchException {
605+ throws IOException , AuthException , LoadAnalyzeException {
549606 for (final Map .Entry <IDeviceID , List <TimeseriesMetadata >> entry :
550607 device2TimeSeriesMetadataList .entrySet ()) {
551608 final IDeviceID device = entry .getKey ();
@@ -647,14 +704,14 @@ public void flushAndClearDeviceIsAlignedCacheIfNecessary() throws SemanticExcept
647704 schemaCache .clearDeviceIsAlignedCacheIfNecessary ();
648705 }
649706
650- public void flush () throws AuthException , LoadAnalyzeTypeMismatchException {
707+ public void flush () throws AuthException , LoadAnalyzeException {
651708 doAutoCreateAndVerify ();
652709
653710 schemaCache .clearTimeSeries ();
654711 }
655712
656713 private void doAutoCreateAndVerify ()
657- throws SemanticException , AuthException , LoadAnalyzeTypeMismatchException {
714+ throws SemanticException , AuthException , LoadAnalyzeException {
658715 if (schemaCache .getDevice2TimeSeries ().isEmpty ()) {
659716 return ;
660717 }
@@ -677,6 +734,15 @@ private void doAutoCreateAndVerify()
677734 }
678735 } catch (AuthException | LoadAnalyzeTypeMismatchException e ) {
679736 throw e ;
737+ } catch (LoadAnalyzeMissingSchemaException e ) {
738+ if (isTemporaryUnavailableDueToPipeSchemaNotReady (e )) {
739+ throw e ;
740+ }
741+ LOGGER .warn ("Auto create or verify schema error." , e );
742+ throw new SemanticException (
743+ String .format (
744+ "Auto create or verify schema error when executing statement %s. Detail: %s." ,
745+ loadTsFileStatement , e .getMessage ()));
680746 } catch (Exception e ) {
681747 if (e .getCause () instanceof LoadAnalyzeTypeMismatchException && isConvertOnTypeMismatch ) {
682748 throw (LoadAnalyzeTypeMismatchException ) e .getCause ();
@@ -863,10 +929,10 @@ private void verifySchema(ISchemaTree schemaTree)
863929 .collect (Collectors .toList ()));
864930
865931 if (iotdbDeviceSchemaInfo == null ) {
866- throw new LoadAnalyzeException (
932+ throw new LoadAnalyzeMissingSchemaException (
867933 String .format (
868934 "Device %s does not exist in IoTDB and can not be created. "
869- + "Please check weather auto-create-schema is enabled." ,
935+ + "Please check whether auto-create-schema is enabled." ,
870936 device ));
871937 }
872938
@@ -889,10 +955,10 @@ private void verifySchema(ISchemaTree schemaTree)
889955 final MeasurementSchema tsFileSchema = tsfileTimeseriesSchemas .get (i );
890956 final MeasurementSchema iotdbSchema = iotdbTimeseriesSchemas .get (i );
891957 if (iotdbSchema == null ) {
892- throw new LoadAnalyzeException (
958+ throw new LoadAnalyzeMissingSchemaException (
893959 String .format (
894960 "Measurement %s does not exist in IoTDB and can not be created. "
895- + "Please check weather auto-create-schema is enabled." ,
961+ + "Please check whether auto-create-schema is enabled." ,
896962 device + TsFileConstant .PATH_SEPARATOR + tsfileTimeseriesSchemas .get (i )));
897963 }
898964
0 commit comments