muttakin2301/ccr2000 huggingface dataset:
Code review comment: Just a question, how will we handle error if we could `actionCompleted.compareAndSet(false, true)` but throwing a unchecked exception within the suceess statement.

Code under review:
public void run() {
            LOG.debug("starting attempt {}", attemptNumber);
            if (!actionCompleted.get()) {
                Optional<ScheduledFuture<?>> timeoutFuture = scheduleTimeout();
                try {
                    Result result = action.tryExecute();
                    if (actionCompleted.compareAndSet(false, true)) {
                        LOG.debug("succeeded with {} attempts", attemptNumber);
                        action.completeWithResult(result);
                        attemptsPerTaskHistogram.update(attemptNumber);
                    } else {
                        LOG.debug(
                                "discard unnecessarily uploaded state, attempt {}", attemptNumber);
                        try {
                            action.discardResult(result);
                        } catch (Exception e) {
                            LOG.warn("unable to discard execution attempt result", e);
                        }
                    }
                } catch (Exception e) {
                    handleError(e);
                } finally {
                    timeoutFuture.ifPresent(f -> f.cancel(true));
                }
            }
        }

Line commented on: handleError(e);

Revised code:
public void run() {
            LOG.debug("starting attempt {}", attemptNumber);
            if (actionCompleted.get()) {
                return;
            }
            Optional<ScheduledFuture<?>> timeoutFuture = scheduleTimeout();
            try {
                Result result = action.tryExecute();
                if (actionCompleted.compareAndSet(false, true)) {
                    LOG.debug("succeeded with {} attempts", attemptNumber);
                    action.completeWithResult(result);
                    attemptsPerTaskHistogram.update(attemptNumber);
                } else {
                    LOG.debug("discard unnecessarily uploaded state, attempt {}", attemptNumber);
                    try {
                        action.discardResult(result);
                    } catch (Exception e) {
                        LOG.warn("unable to discard execution attempt result", e);
                    }
                }
            } catch (Exception e) {
                handleError(e);
            } finally {
                timeoutFuture.ifPresent(f -> f.cancel(true));
            }
        }
Code review comment: This isn't in sync with what is deployed now, but we should never trigger things that haven't already passed this check at triggering-time. I will fix this when I add specific versions for system and staging tests, based on what will be deployed in production.

Code under review:
private void validateChange(Application application, ZoneId zone, Version version) {
        if ( ! application.deploymentJobs().isDeployableTo(zone.environment(), application.change())) {
            throw new IllegalArgumentException("Rejecting deployment of " + application + " to " + zone +
                                               " as " + application.change() + " is not tested");
        }
        
        Deployment existingDeployment = application.deployments().get(zone);
        if (zone.environment().isProduction() && existingDeployment != null &&
            existingDeployment.version().isAfter(version)) {
            throw new IllegalArgumentException("Rejecting deployment of " + application + " to " + zone +
                                               " as the requested version " + version + " is older than" +
                                               " the current version " + existingDeployment.version());
        }
    }

Line commented on: if ( ! application.deploymentJobs().isDeployableTo(zone.environment(), application.change())) {

Revised code:
private void validateChange(Application application, ZoneId zone, Version version) {
        if ( ! application.deploymentJobs().isDeployableTo(zone.environment(), application.change())) {
            throw new IllegalArgumentException("Rejecting deployment of " + application + " to " + zone +
                                               " as " + application.change() + " is not tested");
        }
        
        Deployment existingDeployment = application.deployments().get(zone);
        if (zone.environment().isProduction() && existingDeployment != null &&
            existingDeployment.version().isAfter(version)) {
            throw new IllegalArgumentException("Rejecting deployment of " + application + " to " + zone +
                                               " as the requested version " + version + " is older than" +
                                               " the current version " + existingDeployment.version());
        }
    }
Code review comment: Though is it safe to reuse the same flux for each iteration?  Or is the flux "used up" after the first upload so we would need to create a new one every time?

Code under review:
public Mono<Void> runAsync() {
        return blobAsyncClient.upload(randomByteBufferFlux, null, true).then();
    }

Line commented on: return blobAsyncClient.upload(randomByteBufferFlux, null, true).then();

Revised code:
public Mono<Void> runAsync() {
        return blobAsyncClient.upload(randomByteBufferFlux, null, true).then();
    }
Code review comment: ```suggestion     Optional<Module> jamm = ModuleLayer.boot().findModule("jamm");     if (!jamm.isPresent()) {       ... log warning about expected to find jamm module ...       return;     } ```

Code under review:
public static void premain(String argument, Instrumentation instrumentation) {
    Set<Module> modulesToOpen = new HashSet<>();
    Module jamm = ModuleLayer.boot().findModule("jamm").orElse(null);
    ModuleLayer.boot()
        .modules()
        .forEach(
            module -> {
              if (!module.getDescriptor().isOpen()) {
                modulesToOpen.add(module);
              }
            });

    if (jamm != null) {
      Set<Module> openModules = Set.of(jamm);
      for (Module module : modulesToOpen) {
        Map<String, Set<Module>> addOpens = new HashMap<>();
        for (String pkg : module.getPackages()) {
          addOpens.put(pkg, openModules);
        }
        instrumentation.redefineModule(
            module,
            Collections.emptySet(),
            Collections.emptyMap(),
            addOpens,
            Collections.emptySet(),
            Collections.emptyMap());
      }
    }
  }

Line commented on: Module jamm = ModuleLayer.boot().findModule("jamm").orElse(null);

Revised code:
public static void premain(String argument, Instrumentation instrumentation) {
    Set<Module> modulesToOpen = new HashSet<>();
    Optional<Module> jamm = ModuleLayer.boot().findModule("jamm");
    if (!jamm.isPresent()) {
      System.err.println("Jamm module expected, but not found");
      return;
    }

    ModuleLayer.boot()
        .modules()
        .forEach(
            module -> {
              if (!module.getDescriptor().isOpen()) {
                modulesToOpen.add(module);
              }
            });

    Set<Module> openModules = Set.of(jamm.get());
    for (Module module : modulesToOpen) {
      Map<String, Set<Module>> addOpens = new HashMap<>();
      for (String pkg : module.getPackages()) {
        addOpens.put(pkg, openModules);
      }
      instrumentation.redefineModule(
          module,
          Collections.emptySet(),
          Collections.emptyMap(),
          addOpens,
          Collections.emptySet(),
          Collections.emptyMap());
    }
  }
Code review comment: Sure thing, I will do that!

Code under review:
public Object create() {
        RestClientBuilder builder = RestClientBuilder.newBuilder();
        String baseUrl = getBaseUrl();
        try {
            return builder.baseUrl(new URL(baseUrl)).build(proxyType);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("The value of URL was invalid " + baseUrl);
        } catch (Exception e) {
            if ("com.oracle.svm.core.jdk.UnsupportedFeatureError".equals(e.getClass().getCanonicalName())) {
                throw new IllegalArgumentException(baseUrl + " requires SSL support but it is disabled. You probably have set shamrock.ssl.native to false.");
            }
            throw e;
        }
    }

Line commented on: throw new IllegalArgumentException(baseUrl + " requires SSL support but it is disabled. You probably have set shamrock.ssl.native to false.");

Revised code:
public Object create() {
        RestClientBuilder builder = RestClientBuilder.newBuilder();
        String baseUrl = getBaseUrl();
        try {
            return builder.baseUrl(new URL(baseUrl)).build(proxyType);
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("The value of URL was invalid " + baseUrl);
        } catch (Exception e) {
            if ("com.oracle.svm.core.jdk.UnsupportedFeatureError".equals(e.getClass().getCanonicalName())) {
                throw new IllegalArgumentException(baseUrl + " requires SSL support but it is disabled. You probably have set shamrock.ssl.native to false.");
            }
            throw e;
        }
    }
Code review comment: Consider adding an assert for the number of dispatchers to ensure that we actually check something in the loop.

Code under review:
public void requireThatDispatchTuningIsApplied() throws ParseException {
        ContentCluster cluster = newContentCluster(joinLines("<search>", "</search>"),
                joinLines("<tuning>",
                        "</tuning>"));
        for (Dispatch tld : cluster.getSearch().getIndexed().getTLDs()) {
            PartitionsConfig.Builder builder = new PartitionsConfig.Builder();
            tld.getConfig(builder);
            PartitionsConfig config = new PartitionsConfig(builder);
            assertEquals(2, config.dataset(0).searchablecopies());
            assertTrue(config.dataset(0).useroundrobinforfixedrow());
        }
    }

Line commented on: for (Dispatch tld : cluster.getSearch().getIndexed().getTLDs()) {

Revised code:
public void requireThatDispatchTuningIsApplied() throws ParseException {
        ContentCluster cluster = newContentCluster(joinLines("<search>", "</search>"),
                joinLines("<tuning>",
                        "</tuning>"));
        assertEquals(1, cluster.getSearch().getIndexed().getTLDs().size());
        for (Dispatch tld : cluster.getSearch().getIndexed().getTLDs()) {
            PartitionsConfig.Builder builder = new PartitionsConfig.Builder();
            tld.getConfig(builder);
            PartitionsConfig config = new PartitionsConfig(builder);
            assertEquals(2, config.dataset(0).searchablecopies());
            assertTrue(config.dataset(0).useroundrobinforfixedrow());
        }
    }
Code review comment: The most risky bug in this code is: Incorrect handling and combination of OFFSET and LIMIT values.  You can modify the code like this: ``` @@ -367,7 +368,17 @@ protected ParseNode visitQuerySpecification(QuerySpecification node, ParseTreeCo          } else {              resultSelectRelation.setOrderBy(new ArrayList<>());          } -        resultSelectRelation.setLimit((LimitElement) processOptional(node.getLimit(), context)); +         +        LimitElement limitElement = (LimitElement) processOptional(node.getLimit(), context); +        Optional<ParseNode> offsetOptional = processOptional(node.getOffset(), context); +        if (offsetOptional.isPresent()) { +            if (limitElement == null) { +                throw new ParsingException("StarRocks do not support OFFSET without LIMIT now"); +            } +            long offset = ((LimitElement)offsetOptional.get()).getOffset(); +            limitElement = new LimitElement(offset, limitElement.getLimit()); +        } +        resultSelectRelation.setLimit(limitElement);          return resultSelectRelation;      } ```  And adjust the `visitOffset` method to actually produce a `LimitElement` with both an offset and a limit, ensuring it doesn't improperly use `0` for limit: ``` @@ -532,6 +542,12 @@ protected ParseNode visitSortItem(SortItem node, ParseTreeContext context) {                  getNullOrderingType(isAsc, node.getNullOrdering()));      }   +    @Override +    protected ParseNode visitOffset(Offset node, ParseTreeContext context) { +        // Assuming there's a proper way to parse the offset value considering the context +        long offset = ((LiteralExpr) visit(node.getRowCount(), context)).getLongValue(); +        return new LimitElement(offset, Long.MAX_VALUE); // setting a theoretical maximum limit when only offset is specified +    } ```  Explanation: The original code risked incorrect behavior or a crash due to the replacement of a potentially non-null `LimitElement` with a newly created `LimitElement`, disregarding any pre-set limit when combining OFFSET and LIMIT. Additionally, generating a `LimitElement` with a zero limit in the `visitOffset` method would lead to mistaken interpretations, as it could be construed as "no results should be returned" instead of "no specific limit on the number of results after the offset".

Code under review:
protected ParseNode visitLimit(Limit node, ParseTreeContext context) {
        long limit = ((LiteralExpr) visit(node.getRowCount(), context)).getLongValue();
        return new LimitElement(0, limit);
    }

Line commented on: long limit = ((LiteralExpr) visit(node.getRowCount(), context)).getLongValue();

Revised code:
protected ParseNode visitLimit(Limit node, ParseTreeContext context) {
        long limit = ((LiteralExpr) visit(node.getRowCount(), context)).getLongValue();
        return new LimitElement(0, limit);
    }
Code review comment: I think it isn't  a good idea to use `getInstance()` here, because this may lead some error if another `Catalog` exist in system, and it is strange to call `getInstance()` to get itself.  In addition I think it is better to limit use of singleton as little as possible.   So, could you find another way to write unit test?

Code under review:
public void createDb(CreateDbStmt stmt) throws DdlException {
        final String clusterName = stmt.getClusterName();
        String fullDbName = stmt.getFullDbName();
        long id = 0L;
        if (!tryLock(false)) {
            throw new DdlException("Failed to acquire catalog lock. Try again");
        }
        try {
            if (!nameToCluster.containsKey(clusterName)) {
                ErrorReport.reportDdlException(ErrorCode.ERR_CLUSTER_NO_SELECT_CLUSTER, clusterName);
            }
            if (fullNameToDb.containsKey(fullDbName)) {
                if (stmt.isSetIfNotExists()) {
                    LOG.info("create database[{}] which already exists", fullDbName);
                    return;
                } else {
                    ErrorReport.reportDdlException(ErrorCode.ERR_DB_CREATE_EXISTS, fullDbName);
                }
            } else {
                id = getNextId();
                Database db = new Database(id, fullDbName);
                db.setClusterName(clusterName);
                unprotectCreateDb(db);
                Catalog.getInstance().getEditLog().logCreateDb(db);
            }
        } finally {
            unlock();
        }
        LOG.info("createDb dbName = " + fullDbName + ", id = " + id);
    }

Line commented on: Catalog.getInstance().getEditLog().logCreateDb(db);

Revised code:
public void createDb(CreateDbStmt stmt) throws DdlException {
        final String clusterName = stmt.getClusterName();
        String fullDbName = stmt.getFullDbName();
        long id = 0L;
        if (!tryLock(false)) {
            throw new DdlException("Failed to acquire catalog lock. Try again");
        }
        try {
            if (!nameToCluster.containsKey(clusterName)) {
                ErrorReport.reportDdlException(ErrorCode.ERR_CLUSTER_NO_SELECT_CLUSTER, clusterName);
            }
            if (fullNameToDb.containsKey(fullDbName)) {
                if (stmt.isSetIfNotExists()) {
                    LOG.info("create database[{}] which already exists", fullDbName);
                    return;
                } else {
                    ErrorReport.reportDdlException(ErrorCode.ERR_DB_CREATE_EXISTS, fullDbName);
                }
            } else {
                id = getNextId();
                Database db = new Database(id, fullDbName);
                db.setClusterName(clusterName);
                unprotectCreateDb(db);
                editLog.logCreateDb(db);
            }
        } finally {
            unlock();
        }
        LOG.info("createDb dbName = " + fullDbName + ", id = " + id);
    }
Code review comment: I think it could just be removed, due to other list will not deal with 404.

Code under review:
public PagedFlux<VirtualMachineExtensionImage> listByRegionAsync(String regionName) {
        return PagedConverter
            .flatMapPage(
                publishers.listByRegionAsync(regionName),
                virtualMachinePublisher ->
                    virtualMachinePublisher
                        .extensionTypes()
                        .listAsync()
                        .onErrorResume(ManagementException.class,
                            e -> e.getResponse().getStatusCode() == 404 ? Flux.empty() : Flux.error(e))
                        .flatMap(virtualMachineExtensionImageType ->
                            virtualMachineExtensionImageType.versions().listAsync())
                        .flatMap(VirtualMachineExtensionImageVersion::getImageAsync));
    }

Line commented on: e -> e.getResponse().getStatusCode() == 404 ? Flux.empty() : Flux.error(e))

Revised code:
public PagedFlux<VirtualMachineExtensionImage> listByRegionAsync(String regionName) {
        return PagedConverter
            .flatMapPage(
                publishers.listByRegionAsync(regionName),
                virtualMachinePublisher ->
                    virtualMachinePublisher
                        .extensionTypes()
                        .listAsync()
                        .onErrorResume(ManagementException.class,
                            e -> e.getResponse().getStatusCode() == 404 ? Flux.empty() : Flux.error(e))
                        .flatMap(virtualMachineExtensionImageType ->
                            virtualMachineExtensionImageType.versions().listAsync())
                        .flatMap(VirtualMachineExtensionImageVersion::getImageAsync));
    }
Code review comment: Duh, I should have checked that, thanks! :)

Code under review:
public String finalName() {
        if (finalName == null || finalName.length() == 0)
            return project.getName() + "-" + project.getVersion();
        else
            return finalName;
    }

Line commented on: return project.getName() + "-" + project.getVersion();

Revised code:
public String finalName() {
        if (finalName == null || finalName.length() == 0)
            return project.getName() + "-" + project.getVersion();
        else
            return finalName;
    }
Code review comment: Ah, didn't see that it's printing the file path. In that case, we don't need the word `module`.

Code under review:
public static FunctionInfo getMainFunctionInfo(PackageInfo entryPkgInfo) {
        String errorMsg = "'main' function not found in '" + entryPkgInfo.getProgramFile().getProgramFilePath() + "'";

        FunctionInfo functionInfo = entryPkgInfo.getFunctionInfo(MAIN_FUNCTION_NAME);
        if (functionInfo == null) {
            throw new BLangUsageException(errorMsg);
        }
        return functionInfo;
    }

Line commented on: String errorMsg = "'main' function not found in '" + entryPkgInfo.getProgramFile().getProgramFilePath() + "'";

Revised code:
public static FunctionInfo getMainFunctionInfo(PackageInfo entryPkgInfo) {
        String errorMsg = "'main' function not found in '" + entryPkgInfo.getProgramFile().getProgramFilePath() + "'";

        FunctionInfo functionInfo = entryPkgInfo.getFunctionInfo(MAIN_FUNCTION_NAME);
        if (functionInfo == null) {
            throw new BLangUsageException(errorMsg);
        }
        return functionInfo;
    }
Code review comment: I haven't understood the control flow here. Is this line really executed? Did you want to put it into `finally`?

Code under review:
public void testBufferRecycledOnFailure() throws IOException {
		FailingChannelStateSerializer serializer = new FailingChannelStateSerializer();
		TestRecoveredChannelStateHandler handler = new TestRecoveredChannelStateHandler();

		try (FSDataInputStream stream = geStream(serializer, 10)) {
			new ChannelStateChunkReader(serializer).readChunk(stream, serializer.getHeaderLength(), handler, "channelInfo");
			checkState(serializer.failed);
			checkState(!handler.requestedBuffers.isEmpty());
		} finally {
			assertTrue(handler.requestedBuffers.stream().allMatch(TestChannelStateByteBuffer::isRecycled));
		}
	}

Line commented on: checkState(serializer.failed);

Revised code:
public void testBufferRecycledOnFailure() throws IOException, InterruptedException {
		FailingChannelStateSerializer serializer = new FailingChannelStateSerializer();
		TestRecoveredChannelStateHandler handler = new TestRecoveredChannelStateHandler();

		try (FSDataInputStream stream = getStream(serializer, 10)) {
			new ChannelStateChunkReader(serializer).readChunk(stream, serializer.getHeaderLength(), handler, "channelInfo");
		} finally {
			checkState(serializer.failed);
			checkState(!handler.requestedBuffers.isEmpty());
			assertTrue(handler.requestedBuffers.stream().allMatch(TestChannelStateByteBuffer::isRecycled));
		}
	}
Code review comment: If it's not necessary, I don't see why we would do this.  Registering types for reflection has a cost.

Code under review:
void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
        
        
        
        final String driverName = "org.postgresql.Driver";
        reflectiveClass.produce(ReflectiveClassBuildItem.builder(driverName).build());

        
        
        
        
        final String[] pgObjectClasses = new String[] {
                "org.postgresql.util.PGobject",
                "org.postgresql.util.PGInterval",
                "org.postgresql.util.PGmoney",
                "org.postgresql.geometric.PGbox",
                "org.postgresql.geometric.PGcircle",
                "org.postgresql.geometric.PGline",
                "org.postgresql.geometric.PGlseg",
                "org.postgresql.geometric.PGpath",
                "org.postgresql.geometric.PGpoint",
                "org.postgresql.geometric.PGpolygon",
                
                
                "org.postgresql.jdbc.PgResultSet.NullObject"
        };
        for (String pgObjectClass : pgObjectClasses) {
            reflectiveClass.produce(ReflectiveClassBuildItem.builder(pgObjectClass).build());
        }

        
        reflectiveClass.produce(ReflectiveClassBuildItem.builder("org.postgresql.ds.common.BaseDataSource").constructors(false)
                .methods().build());
    }

Line commented on: "org.postgresql.jdbc.PgResultSet.NullObject"

Revised code:
void build(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
        
        
        
        final String driverName = "org.postgresql.Driver";
        reflectiveClass.produce(ReflectiveClassBuildItem.builder(driverName).build());

        
        
        
        
        final String[] pgObjectClasses = new String[] {
                "org.postgresql.util.PGobject",
                "org.postgresql.util.PGInterval",
                "org.postgresql.util.PGmoney",
                "org.postgresql.geometric.PGbox",
                "org.postgresql.geometric.PGcircle",
                "org.postgresql.geometric.PGline",
                "org.postgresql.geometric.PGlseg",
                "org.postgresql.geometric.PGpath",
                "org.postgresql.geometric.PGpoint",
                "org.postgresql.geometric.PGpolygon",
                
                
                
        };
        reflectiveClass.produce(ReflectiveClassBuildItem.builder(pgObjectClasses).build());

        
        reflectiveClass.produce(ReflectiveClassBuildItem.builder("org.postgresql.ds.common.BaseDataSource").constructors(false)
                .methods().build());
    }
Code review comment: > Good catch and thanks for your contribution. Only two minor comments left, please consider to modify the error message.  ok, have modified.

Code under review:
public DataStreamSource<String> readTextFile(String filePath, String charsetName) {
		Preconditions.checkArgument(!StringUtils.isNullOrWhitespaceOnly(filePath), "The file path must not be blank.");

		TextInputFormat format = new TextInputFormat(new Path(filePath));
		format.setFilesFilter(FilePathFilter.createDefaultFilter());
		TypeInformation<String> typeInfo = BasicTypeInfo.STRING_TYPE_INFO;
		format.setCharsetName(charsetName);

		return readFile(format, filePath, FileProcessingMode.PROCESS_ONCE, -1, typeInfo);
	}

Line commented on: Preconditions.checkArgument(!StringUtils.isNullOrWhitespaceOnly(filePath), "The file path must not be blank.");

Revised code:
public DataStreamSource<String> readTextFile(String filePath, String charsetName) {
		Preconditions.checkArgument(!StringUtils.isNullOrWhitespaceOnly(filePath), "The file path must not be null or blank.");

		TextInputFormat format = new TextInputFormat(new Path(filePath));
		format.setFilesFilter(FilePathFilter.createDefaultFilter());
		TypeInformation<String> typeInfo = BasicTypeInfo.STRING_TYPE_INFO;
		format.setCharsetName(charsetName);

		return readFile(format, filePath, FileProcessingMode.PROCESS_ONCE, -1, typeInfo);
	}
Code review comment: @FroMage Right, but the `referer` header has a single value, or have I missed your point ? I mean, this referer check is not guaranteed to succeed, but it is not a big problem - since the only thing we are deciding upon here is how to fail, see my response to Pedro as well: whether to return `401` immediately or redirect the user back to the OIDC provider to sign in again

Code under review:
private boolean isRedirectFromProvider(RoutingContext context, TenantConfigContext configContext) {
        String referer = context.request().getHeader(HttpHeaders.REFERER);
        return referer != null && referer.startsWith(configContext.provider.getMetadata().getAuthorizationUri());
    }

Line commented on: return referer != null && referer.startsWith(configContext.provider.getMetadata().getAuthorizationUri());

Revised code:
private boolean isRedirectFromProvider(RoutingContext context, TenantConfigContext configContext) {
        String referer = context.request().getHeader(HttpHeaders.REFERER);
        return referer != null && referer.startsWith(configContext.provider.getMetadata().getAuthorizationUri());
    }
Code review comment: ```suggestion   @FunctionalInterface   public interface RangeEndEstimator {     long estimate();   } ```

Code under review:
public SplitResult<OffsetRange> trySplit(double fractionOfRemainder) {
    
    if (range.getTo() != Long.MAX_VALUE || range.getTo() == range.getFrom()) {
      return super.trySplit(fractionOfRemainder);
    }
    long cur = (lastAttemptedOffset == null) ? range.getFrom() - 1 : lastAttemptedOffset;

    
    if (cur == Long.MAX_VALUE) {
      return null;
    }
    
    
    long estimateLatestOffset = Long.max(poller.estimateRangeEnd(), cur + 1);
    long splitPos =
        cur
            + Math.max(
                1L,
                (Double.valueOf((estimateLatestOffset - cur) * fractionOfRemainder)).longValue());

    if (splitPos > estimateLatestOffset) {
      return null;
    }
    OffsetRange res = new OffsetRange(splitPos, range.getTo());
    this.range = new OffsetRange(range.getFrom(), splitPos);
    return SplitResult.of(range, res);
  }

Line commented on: long cur = (lastAttemptedOffset == null) ? range.getFrom() - 1 : lastAttemptedOffset;

Revised code:
public SplitResult<OffsetRange> trySplit(double fractionOfRemainder) {
    
    if (range.getTo() != Long.MAX_VALUE || range.getTo() == range.getFrom()) {
      return super.trySplit(fractionOfRemainder);
    }
    
    if (lastAttemptedOffset != null && lastAttemptedOffset == Long.MAX_VALUE) {
      return null;
    }
    BigDecimal cur =
        (lastAttemptedOffset == null)
            ? BigDecimal.valueOf(range.getFrom()).subtract(BigDecimal.ONE, MathContext.DECIMAL128)
            : BigDecimal.valueOf(lastAttemptedOffset);

    
    
    BigDecimal estimateRangeEnd =
        BigDecimal.valueOf(rangeEndEstimator.estimate())
            .max(cur.add(BigDecimal.ONE, MathContext.DECIMAL128));

    
    
    
    BigDecimal splitPos =
        cur.add(
            estimateRangeEnd
                .subtract(cur, MathContext.DECIMAL128)
                .multiply(BigDecimal.valueOf(fractionOfRemainder), MathContext.DECIMAL128)
                .max(BigDecimal.ONE),
            MathContext.DECIMAL128);
    long split = splitPos.longValue();
    if (split > estimateRangeEnd.longValue()) {
      return null;
    }
    OffsetRange res = new OffsetRange(split, range.getTo());
    this.range = new OffsetRange(range.getFrom(), split);
    return SplitResult.of(range, res);
  }
Code review comment: I agree, but without the refactoring, I don't think we can avoid spaghetti.  I'd suggest to do a refactoring as a separate task.

Code under review:
void randomEmit(T record, int targetChannelIndex) throws IOException, InterruptedException {
		tryFinishCurrentBufferBuilder(targetChannelIndex);

		randomTriggered = true;
		emit(record, targetChannelIndex);
		randomTriggered = false;

		if (bufferBuilder != null) {
			for (int index = 0; index < numberOfChannels; index++) {
				if (index != targetChannelIndex) {
					addBufferConsumer(randomTriggeredConsumer.copyAndSync(bufferBuilder), index);
				}
			}
		}
	}

Line commented on: addBufferConsumer(randomTriggeredConsumer.copyAndSync(bufferBuilder), index);

Revised code:
void randomEmit(T record, int targetChannelIndex) throws IOException, InterruptedException {
		tryFinishCurrentBufferBuilder(targetChannelIndex);

		randomTriggered = true;
		emit(record, targetChannelIndex);
		randomTriggered = false;

		if (bufferBuilder != null) {
			for (int index = 0; index < numberOfChannels; index++) {
				if (index != targetChannelIndex) {
					addBufferConsumer(randomTriggeredConsumer.copyWithReaderPosition(bufferBuilder.getCommittedBytes()), index);
				}
			}
		}
	}
Code review comment: Shall we remove this `PackageFile.MAGIC_VALUE` & `PackageFile.LANG_VERSION` as they are not used in other places? Can be done through another PR as well.

Code under review:
public static byte[] writePackage(PackageFile packageFile) throws IOException {
        ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
        try (DataOutputStream dataOutStream = new DataOutputStream(byteArrayOS)) {
            dataOutStream.write(packageFile.pkgBinaryContent);
            return byteArrayOS.toByteArray();
        }
    }

Line commented on: dataOutStream.write(packageFile.pkgBinaryContent);

Revised code:
public static byte[] writePackage(PackageFile packageFile) throws IOException {
        ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
        try (DataOutputStream dataOutStream = new DataOutputStream(byteArrayOS)) {
            dataOutStream.write(packageFile.pkgBinaryContent);
            return byteArrayOS.toByteArray();
        }
    }
Code review comment: Ah sorry about that, thank you

Code under review:
public BigDecimal toInputType(BigDecimal base) {
    checkArgument(
        base == null
            || (base.precision() <= precision && base.scale() <= scale)
            
            || base.round(new MathContext(precision)).compareTo(base) == 0,
        "Expected BigDecimal base to be null or have precision <= %s (was %s), scale <= %s (was %s)",
        precision,
        (base == null) ? null : base.precision(),
        scale,
        (base == null) ? null : base.scale());
    return base;
  }

Line commented on: return base;

Revised code:
public BigDecimal toInputType(BigDecimal base) {
    if (precision != -1) {
      
      checkArgument(
          base == null
              || (base.precision() <= precision && base.scale() <= scale)
              || base.round(new MathContext(precision)).compareTo(base) == 0,
          "Expected BigDecimal base to be null or have precision <= %s (was %s), scale <= %s (was %s)",
          precision,
          (base == null) ? null : base.precision(),
          scale,
          (base == null) ? null : base.scale());
    }
    return base;
  }
Code review comment: nit: consistent use of `this`. In the method above, you did not reference member variables with `this`. In general, unless there is a naming conflict, I would remove `this`.

Code under review:
public String getFullyQualifiedNamespace() {
        return this.endpoint.getHost();
    }

Line commented on: return this.endpoint.getHost();

Revised code:
public String getFullyQualifiedNamespace() {
        return endpoint.getHost();
    }
Code review comment: Do you know what's expected here? When used in distributed mode, the protocol is a hand-made protocol on top of TCP.

Code under review:
protected String protocol(final Message message) {
            return null;
        }

Line commented on: return null;

Revised code:
protected String protocol(final Message message) {
            return null;
        }
Code review comment: But how can this floating credit be assigned to this blocked `RemoteInputChannel`? Wouldn't it cause the same deadlock, when floating buffers are assigned to blocked channels and job/task can not make any progress?  It sounds like maybe this should have been handled sooner when trying to increase `unannouncedCredit`?

Code under review:
public void resumeConsumption() throws IOException {
        checkState(!isReleased.get(), "Channel released.");
        checkPartitionRequestQueueInitialized();

        if (initialCredit == 0) {
            unannouncedCredit.set(0);
        }

        
        
        partitionRequestClient.resumeConsumption(this);
    }

Line commented on: partitionRequestClient.resumeConsumption(this);

Revised code:
public void resumeConsumption() throws IOException {
        checkState(!isReleased.get(), "Channel released.");
        checkPartitionRequestQueueInitialized();

        if (initialCredit == 0) {
            
            
            
            
            
            unannouncedCredit.set(0);
        }

        
        
        partitionRequestClient.resumeConsumption(this);
    }
Code review comment: This should check for `startsWith` instead of `equals` as sometimes the service returns `text/event-stream; charset=utf8` as the content type.

Code under review:
private static boolean isTextEventStream(okhttp3.Headers responseHeaders) {
        return responseHeaders != null && responseHeaders.get(HeaderName.CONTENT_TYPE.toString()) != null &&
            Objects.equals(responseHeaders.get(HeaderName.CONTENT_TYPE.toString()), ContentType.TEXT_EVENT_STREAM);
    }

Line commented on: Objects.equals(responseHeaders.get(HeaderName.CONTENT_TYPE.toString()), ContentType.TEXT_EVENT_STREAM);

Revised code:
private static boolean isTextEventStream(okhttp3.Headers responseHeaders) {
        if (responseHeaders != null) {
            return ServerSentEventUtil
                .isTextEventStreamContentType(responseHeaders.get(HttpHeaderName.CONTENT_TYPE.toString()));
        }
        return false;
    }
Code review comment: Well -1 == 0xff so I am pretty sure there should not be an issue, I will change it if you think is more readable.

Code under review:
private static byte[] unsignedCopyAndIncrement(byte[] input) {
    byte[] copy = Arrays.copyOf(input, input.length);
    if (copy == null) {
      throw new IllegalArgumentException("cannot increment null array");
    } else {
      for (int i = copy.length - 1; i >= 0; --i) {
        if (copy[i] != -1) {
          ++copy[i];
          return copy;
        }
        copy[i] = 0;
      }
      byte[] out = new byte[copy.length + 1];
      out[0] = 1;
      System.arraycopy(copy, 0, out, 1, copy.length);
      return out;
    }
  }

Line commented on: if (copy[i] != -1) {

Revised code:
private static byte[] unsignedCopyAndIncrement(byte[] input) {
    if (input.length == 0) {
      return new byte[] {0};
    }
    byte[] copy = Arrays.copyOf(input, input.length);
    for (int i = copy.length - 1; i >= 0; --i) {
      if (copy[i] != (byte) 0xff) {
        ++copy[i];
        return copy;
      }
      copy[i] = 0;
    }
    byte[] out = new byte[copy.length + 1];
    out[0] = 1;
    System.arraycopy(copy, 0, out, 1, copy.length);
    return out;
  }
Code review comment: 1. Yes agreed, I have made the change. 2. Shifted `columnMetaDataMap` declaration to `setUp`

Code under review:
public void assertGetColumnMetaDataGivenColumnIndex() {
        List<String> pipelineTableColumns = pipelineTableMetaData.getColumnNames();
        PipelineColumnMetaData actual = columnMetaDataMap.get(pipelineTableColumns.get(0));
        assertThat(actual.getOrdinalPosition(), is(0));
        assertThat(actual.getName(), is("test"));
        assertThat(actual.getDataType(), is(Types.INTEGER));
        assertTrue(actual.isPrimaryKey());
    }

Line commented on: assertThat(actual.getOrdinalPosition(), is(0));

Revised code:
public void assertGetColumnMetaDataGivenColumnIndex() {
        PipelineColumnMetaData actual = pipelineTableMetaData.getColumnMetaData(0);
        assertThat(actual.getOrdinalPosition(), is(1));
        assertThat(actual.getName(), is("test"));
        assertThat(actual.getDataType(), is(Types.INTEGER));
        assertTrue(actual.isPrimaryKey());
    }
Code review comment: Isn't it incomplete though? The state which is usually specified within the quotes isn't specified here?

Code under review:
public SemanticModel getSemanticModel(ModuleId moduleId) {
        ModuleContext moduleContext = this.rootPackageContext.moduleContext(moduleId);
        
        
        if (moduleContext.compilationState() != ModuleCompilationState.COMPILED) {
            throw new IllegalStateException("Semantic model cannot be retrieved when the module is in " +
                    "compilation state'" + (moduleContext.compilationState() == null ? ""
                    : (" " + moduleContext.compilationState().name())) + "'. " +
                    "This is an internal error which will be fixed in a later release.");
        }

        return new BallerinaSemanticModel(moduleContext.bLangPackage(), this.compilerContext);
    }

Line commented on: : (" " + moduleContext.compilationState().name())) + "'. " +

Revised code:
public SemanticModel getSemanticModel(ModuleId moduleId) {
        ModuleContext moduleContext = this.rootPackageContext.moduleContext(moduleId);
        
        
        if (moduleContext.compilationState() != ModuleCompilationState.COMPILED) {
            throw new IllegalStateException("Semantic model cannot be retrieved when the module is in " +
                    "compilation state" + (moduleContext.compilationState() == null ? ""
                    : (" '" + moduleContext.compilationState().name() + "'")) +
                    ". This is an internal error which will be fixed in a later release.");
        }

        return new BallerinaSemanticModel(moduleContext.bLangPackage(), this.compilerContext);
    }
Code review comment: I don't entirely understand the question. Can someone please provide a bit more context?

Code under review:
public CloseHandlesInfo(Integer closedHandles) {
        this.closedHandles = closedHandles;
        this.failedHandles = 0; 
    }

Line commented on: this.failedHandles = 0;

Revised code:
public CloseHandlesInfo(Integer closedHandles) {
        this.closedHandles = closedHandles;
        this.failedHandles = 0;
    }
Code review comment: Hmm that's a good point. It is redundant to specify both - specifying `jdbcType` that conflicts with `driverClassName` won't affect the code path which will uses the `driverClassName` parameter and ignores the `jdbcType`. This just might be misleading behavior, but I can remove the error for now since it isn't technically an error

Code under review:
public void validate() throws IllegalArgumentException {
      if (Strings.isNullOrEmpty(getDriverClassName()) && Strings.isNullOrEmpty(getJdbcType())) {
        throw new IllegalArgumentException(
            "Either JDBC Driver class name or JDBC type must be set.");
      }
      if (Strings.isNullOrEmpty(getJdbcUrl())) {
        throw new IllegalArgumentException("JDBC URL cannot be blank");
      }
      if (!Strings.isNullOrEmpty(getJdbcType())
          && !JDBCTypes.contains(getJdbcType().toLowerCase())) {
        throw new IllegalArgumentException("JDBC type must be one of " + JDBCTypes);
      }

      boolean readQueryPresent = (getReadQuery() != null && !"".equals(getReadQuery()));
      boolean locationPresent = (getLocation() != null && !"".equals(getLocation()));

      if (readQueryPresent && locationPresent) {
        throw new IllegalArgumentException(
            "ReadQuery and Location are mutually exclusive configurations");
      }
      if (!readQueryPresent && !locationPresent) {
        throw new IllegalArgumentException("Either ReadQuery or Location must be set.");
      }
    }

Line commented on: if (Strings.isNullOrEmpty(getDriverClassName()) && Strings.isNullOrEmpty(getJdbcType())) {

Revised code:
public void validate() throws IllegalArgumentException {
      if (Strings.isNullOrEmpty(getJdbcUrl())) {
        throw new IllegalArgumentException("JDBC URL cannot be blank");
      }

      boolean driverClassNamePresent = !Strings.isNullOrEmpty(getDriverClassName());
      boolean jdbcTypePresent = !Strings.isNullOrEmpty(getJdbcType());
      if (driverClassNamePresent && jdbcTypePresent) {
        throw new IllegalArgumentException(
            "JDBC Driver class name and JDBC type are mutually exclusive configurations.");
      }
      if (!driverClassNamePresent && !jdbcTypePresent) {
        throw new IllegalArgumentException(
            "One of JDBC Driver class name or JDBC type must be specified.");
      }
      if (jdbcTypePresent
          && !JDBC_DRIVER_MAP.containsKey(Objects.requireNonNull(getJdbcType()).toLowerCase())) {
        throw new IllegalArgumentException("JDBC type must be one of " + JDBC_DRIVER_MAP.keySet());
      }

      boolean readQueryPresent = (getReadQuery() != null && !"".equals(getReadQuery()));
      boolean locationPresent = (getLocation() != null && !"".equals(getLocation()));

      if (readQueryPresent && locationPresent) {
        throw new IllegalArgumentException(
            "ReadQuery and Location are mutually exclusive configurations");
      }
      if (!readQueryPresent && !locationPresent) {
        throw new IllegalArgumentException("Either ReadQuery or Location must be set.");
      }
    }
Code review comment: FLINK-14869 is opened to track this issue.

Code under review:
public ResourceSpec subtract(final ResourceSpec other) {
		checkNotNull(other, "Cannot subtract null resources");

		if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) {
			return UNKNOWN;
		}

		checkArgument(other.lessThanOrEqual(this), "Cannot subtract a larger ResourceSpec from this one.");

		final ResourceSpec target = new ResourceSpec(
			this.cpuCores.subtract(other.cpuCores),
			this.taskHeapMemory.subtract(other.taskHeapMemory),
			this.taskOffHeapMemory.subtract(other.taskOffHeapMemory),
			this.onHeapManagedMemory.subtract(other.onHeapManagedMemory),
			this.offHeapManagedMemory.subtract(other.offHeapManagedMemory));

		target.extendedResources.putAll(extendedResources);

		for (Resource resource : other.extendedResources.values()) {
			target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> {
				final Resource subtracted = v1.subtract(v2);
				return subtracted.getValue().compareTo(BigDecimal.ZERO) == 0 ? null : subtracted;
			});
		}
		return target;
	}

Line commented on: return subtracted.getValue().compareTo(BigDecimal.ZERO) == 0 ? null : subtracted;

Revised code:
public ResourceSpec subtract(final ResourceSpec other) {
		checkNotNull(other, "Cannot subtract null resources");

		if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) {
			return UNKNOWN;
		}

		checkArgument(other.lessThanOrEqual(this), "Cannot subtract a larger ResourceSpec from this one.");

		final ResourceSpec target = new ResourceSpec(
			this.cpuCores.subtract(other.cpuCores),
			this.taskHeapMemory.subtract(other.taskHeapMemory),
			this.taskOffHeapMemory.subtract(other.taskOffHeapMemory),
			this.onHeapManagedMemory.subtract(other.onHeapManagedMemory),
			this.offHeapManagedMemory.subtract(other.offHeapManagedMemory));

		target.extendedResources.putAll(extendedResources);

		for (Resource resource : other.extendedResources.values()) {
			target.extendedResources.merge(resource.getName(), resource, (v1, v2) -> {
				final Resource subtracted = v1.subtract(v2);
				return subtracted.getValue().compareTo(BigDecimal.ZERO) == 0 ? null : subtracted;
			});
		}
		return target;
	}
Code review comment: Looks like the PR build failed due to spotbugs. So, the fix is working!

Code under review:
private void checkDigestLength(byte[] digest) {
        if (digest.length != getDigestLength()) {
            throw new IllegalArgumentException("Invalid digest length.");
        }
    }

Line commented on: if (digest.length != getDigestLength()) {

Revised code:
private void checkDigestLength(byte[] digest) {
            if (digest.length != getDigestLength()) {
                throw new IllegalArgumentException("Invalid digest length.");
            }
        }
Code review comment: The directories should point to `balo` and `caches` here right?

Code under review:
public void testCleanCommand() {
        CleanCommand cleanCommand = new CleanCommand(Paths.get(System.getProperty("user.dir")), false);
        new CommandLine(cleanCommand).parse("--sourceroot", this.testResources.resolve("valid-project").toString());
        cleanCommand.execute();
        Path bin = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.BIN_DIR_NAME);
        Path balo = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.BIN_DIR_NAME);
        Path caches = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.BIN_DIR_NAME);

        Assert.assertFalse(Files.exists(bin), "Check if bin directory is deleted");
        Assert.assertFalse(Files.exists(balo), "Check if balo directory is deleted");
        Assert.assertFalse(Files.exists(caches), "Check if caches directory is deleted");
    }

Line commented on: + File.separator + ProjectDirConstants.BIN_DIR_NAME);

Revised code:
public void testCleanCommand() {
        CleanCommand cleanCommand = new CleanCommand(Paths.get(System.getProperty("user.dir")), false);
        new CommandLine(cleanCommand).parse("--sourceroot", this.testResources.resolve("valid-project").toString());
        cleanCommand.execute();
        Path bin = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.BIN_DIR_NAME);
        Path balo = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.TARGET_BALO_DIRECTORY);
        Path caches = this.testResources.resolve("valid-project").resolve(ProjectDirConstants.TARGET_DIR_NAME
                + File.separator + ProjectDirConstants.CACHES_DIR_NAME);

        Assert.assertFalse(Files.exists(bin), "Check if bin directory is deleted");
        Assert.assertFalse(Files.exists(balo), "Check if balo directory is deleted");
        Assert.assertFalse(Files.exists(caches), "Check if caches directory is deleted");
    }