muttakin2301/ccr2000 huggingface dataset:
Code review comment: for now, our configuration file can only config one flow of signUpOrSignIn.

Code under review:
public ClientRegistrationRepository clientRegistrationRepository() {
            final List<ClientRegistration> signUpOrSignInRegistrations = new ArrayList<>();
            final List<ClientRegistration> otherRegistrations = new ArrayList<>();


            addB2CClientRegistration(signUpOrSignInRegistrations, properties.getUserFlows().getSignUpOrSignIn());
            addB2CClientRegistration(otherRegistrations, properties.getUserFlows().getProfileEdit());
            addB2CClientRegistration(otherRegistrations, properties.getUserFlows().getPasswordReset());

            return new AADB2CClientRegistrationRepository(signUpOrSignInRegistrations, otherRegistrations);
        }

Line commented on: final List<ClientRegistration> signUpOrSignInRegistrations = new ArrayList<>();

Revised code:
public ClientRegistrationRepository clientRegistrationRepository() {
            final List<ClientRegistration> signUpOrSignInRegistrations = new ArrayList<>(1);
            final List<ClientRegistration> otherRegistrations = new ArrayList<>();


            addB2CClientRegistration(signUpOrSignInRegistrations, properties.getUserFlows().getSignUpOrSignIn());
            addB2CClientRegistration(otherRegistrations, properties.getUserFlows().getProfileEdit());
            addB2CClientRegistration(otherRegistrations, properties.getUserFlows().getPasswordReset());

            return new AADB2CClientRegistrationRepository(signUpOrSignInRegistrations, otherRegistrations);
        }
Code review comment: Why do we want to return OK?  We could let the exception propagate and we'll get the default http 500 page with a stack trace I believe. This will also be the default when Duration parsing or ByteStreams.copy throw an exception.

Code under review:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String durationStr = req.getParameter("duration");
    Duration duration;
    if (durationStr == null) {
      duration = Duration.ofSeconds(60);
    } else {
      duration = Duration.parse(durationStr);
    }

    ServletOutputStream writer = resp.getOutputStream();
    InputStream jfrStream;
    try {
      jfrStream = memoryMonitor.runJfrProfile(duration).get();
    } catch (Exception e) {
      resp.setContentType("text/html;charset=utf-8");
      resp.setStatus(HttpServletResponse.SC_OK);

      writer.println("<html>\nFailed run JFR profile: <br>\n<pre>");
      writer.println(e.toString());
      PrintWriter pw =
          new PrintWriter(
              new BufferedWriter(new OutputStreamWriter(writer, StandardCharsets.UTF_8)));
      e.printStackTrace(pw);
      writer.println("</pre>\n</html>");
      return;
    }

    resp.setContentType("application/octet-stream");
    resp.setHeader("Content-Disposition", "attachment; filename=\"profile.jfr\"");
    ByteStreams.copy(jfrStream, writer);
    resp.setStatus(HttpServletResponse.SC_OK);
  }

Line commented on: resp.setContentType("text/html;charset=utf-8");

Revised code:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String durationStr = req.getParameter("duration");
    Duration duration;
    if (durationStr == null) {
      duration = DEFAULT_RECORDING_DURATION;
    } else {
      duration = Duration.parse(durationStr);
    }

    ServletOutputStream writer = resp.getOutputStream();

    try (InputStream jfrStream = memoryMonitor.runJfrProfile(duration).get()) {
      resp.setContentType("application/octet-stream");
      resp.setHeader("Content-Disposition", "attachment; filename=\"profile.jfr\"");
      ByteStreams.copy(jfrStream, writer);
    } catch (ExecutionException | InterruptedException e) {
      throw new RuntimeException(e);
    }

    resp.setStatus(HttpServletResponse.SC_OK);
  }
Code review comment: Good point, we did not have it previously for segments (maybe because double-release is acceptable for some use cases in Dataset API atm) but it can be useful for debugging, I will add it.

Code under review:
public void releaseMemory(Object owner, MemoryType memoryType, long size) {
		checkMemoryReservationPreconditions(owner, memoryType, size);
		if (size == 0L) {
			return;
		}

		reservedMemory.compute(owner, (o, reservations) -> {
			if (reservations != null) {
				reservations.compute(
					memoryType,
					(mt, currentlyReserved) ->
						currentlyReserved == null || currentlyReserved <= size ? null : currentlyReserved - size);
			}
			
			return reservations == null || reservations.isEmpty() ? null : reservations;
		});
		budgetByType.releaseBudgetForKey(memoryType, size);
	}

Line commented on: currentlyReserved == null || currentlyReserved <= size ? null : currentlyReserved - size);

Revised code:
public void releaseMemory(Object owner, MemoryType memoryType, long size) {
		checkMemoryReservationPreconditions(owner, memoryType, size);
		if (size == 0L) {
			return;
		}

		reservedMemory.compute(owner, (o, reservations) -> {
			if (reservations != null) {
				reservations.compute(
					memoryType,
					(mt, currentlyReserved) -> {
						if (currentlyReserved == null || currentlyReserved < size) {
							LOG.warn(
								"Trying to release more memory {} than it was reserved {} so far for the owner {}",
								size,
								currentlyReserved == null ? 0 : currentlyReserved,
								owner);
							
							return null;
						} else {
							return currentlyReserved - size;
						}
					});
			}
			
			return reservations == null || reservations.isEmpty() ? null : reservations;
		});
		budgetByType.releaseBudgetForKey(memoryType, size);
	}
Code review comment: nit: Do we actually want to check for spaces? Isn't it easy to break?

Code under review:
void testAdditionalFields(@TempDir Path tmpDir) throws Exception {
        final Path file = tmpDir.resolve("openapi_spec.yaml");
        OpenApiSpecGenerator.createDocumentationFile(
                "title", new TestAdditionalFieldsRestEndpoint(), RuntimeRestAPIVersion.V0, file);
        final String actual = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
        assertThat(actual)
                .contains(
                        "    AdditionalFieldsRequestBody:\n"
                                + "      type: object\n"
                                + "      additionalProperties:\n"
                                + "        type: string");
    }

Line commented on: + "        type: string");

Revised code:
void testAdditionalFields(@TempDir Path tmpDir) throws Exception {
        final OpenAPI documentation =
                OpenApiSpecGenerator.createDocumentation(
                        "title", new TestAdditionalFieldsRestEndpoint(), RuntimeRestAPIVersion.V0);
        assertThat(documentation.getComponents().getSchemas())
                .extractingByKey("AdditionalFieldsRequestBody")
                .satisfies(
                        x ->
                                assertThat(x.getAdditionalProperties())
                                        .isInstanceOf(StringSchema.class));
    }
Code review comment: this can result in odd race conditions, where one thread has set the shutdownFuture, but another one the failureCause. I would suggest to create a container for the future and exception and update them atomically.

Code under review:
private CompletableFuture<Void> close(Throwable cause) {
			final CompletableFuture<Void> shutdownFuture = new CompletableFuture<>();

			if (connectionShutdownFuture.compareAndSet(null, shutdownFuture) &&
					failureCause.compareAndSet(null, cause)) {

				channel.close().addListener(finished -> {
					stats.reportInactiveConnection();
					for (long requestId : pendingRequests.keySet()) {
						TimestampedCompletableFuture pending = pendingRequests.remove(requestId);
						if (pending != null && pending.completeExceptionally(cause)) {
							stats.reportFailedRequest();
						}
					}

					if (finished.isSuccess()) {
						shutdownFuture.complete(null);
					} else {
						shutdownFuture.completeExceptionally(finished.cause());
					}
				});
			}

			
			return connectionShutdownFuture.get();
		}

Line commented on: if (connectionShutdownFuture.compareAndSet(null, shutdownFuture) &&

Revised code:
private CompletableFuture<Void> close(Throwable cause) {
			CompletableFuture<Void> future = new CompletableFuture<>();
			if (connectionShutdownFuture.compareAndSet(null, future)) {
				synchronized (connectLock) {
					if (failureCause == null) {
						failureCause = cause;
					}

					if (established != null) {
						established.close().whenComplete((result, throwable) -> {
							if (throwable != null) {
								future.completeExceptionally(throwable);
							} else {
								future.complete(null);
							}
						});
					} else {
						PendingRequest pending;
						while ((pending = queuedRequests.poll()) != null) {
							pending.completeExceptionally(cause);
						}
						future.complete(null);
					}
				}
			}
			return connectionShutdownFuture.get();
		}
Code review comment: I used `HeapMemorySegment` in tests so buffers are freed when the method finishes at the latest.  `recycleBuffer()` would just make them eligible for GC a couple of instructions earlier.

Code under review:
public void testAddEventBuffer() {
		NetworkBuffer dataBuf = getBuffer();
		NetworkBuffer eventBuf = getBuffer();
		eventBuf.tagAsEvent();
		ChannelStateWriterImpl writer = openWriter();
		callStart(writer);
		try {
			writer.addInputData(CHECKPOINT_ID, new InputChannelInfo(1, 1), 1, eventBuf, dataBuf);
		} finally {
			assertTrue(dataBuf.isRecycled());
		}
	}

Line commented on: assertTrue(dataBuf.isRecycled());

Revised code:
public void testAddEventBuffer() {
		NetworkBuffer dataBuf = getBuffer();
		NetworkBuffer eventBuf = getBuffer();
		eventBuf.tagAsEvent();
		ChannelStateWriterImpl writer = openWriter();
		callStart(writer);
		try {
			writer.addInputData(CHECKPOINT_ID, new InputChannelInfo(1, 1), 1, eventBuf, dataBuf);
		} finally {
			assertTrue(dataBuf.isRecycled());
		}
	}
Code review comment: When ConnectContext.get() will appear Null， and what different with context default session variable and ConnectContext.get().getSessionVariable()?

Code under review:
public static ConnectContext buildConnectContext() {
        ConnectContext context = new ConnectContext();
        
        
        
        context.getSessionVariable().setReportSuccess(false);
        int parallel = context.getSessionVariable().getStatisticCollectParallelism();
        if (null != ConnectContext.get()) {
            parallel = ConnectContext.get().getSessionVariable().getStatisticCollectParallelism();
        }
        context.getSessionVariable().setParallelExecInstanceNum(parallel);
        context.getSessionVariable().setPipelineDop(1);
        
        context.getSessionVariable().setEnablePipelineEngine(false);
        context.setCluster(SystemInfoService.DEFAULT_CLUSTER);
        context.setDatabase(Constants.StatisticsDBName);
        context.setCatalog(GlobalStateMgr.getCurrentState());
        context.setCurrentUserIdentity(UserIdentity.ROOT);
        context.setQualifiedUser(UserIdentity.ROOT.getQualifiedUser());
        context.setQueryId(UUIDUtil.genUUID());
        context.setExecutionId(UUIDUtil.toTUniqueId(context.getQueryId()));
        context.setThreadLocalInfo();
        context.setStartTime();
        return context;
    }

Line commented on: if (null != ConnectContext.get()) {

Revised code:
public static ConnectContext buildConnectContext() {
        ConnectContext context = new ConnectContext();
        
        
        
        context.getSessionVariable().setReportSuccess(false);
        int parallel = context.getSessionVariable().getStatisticCollectParallelism();
        if (null != ConnectContext.get()) {
            
            parallel = ConnectContext.get().getSessionVariable().getStatisticCollectParallelism();
        }
        context.getSessionVariable().setParallelExecInstanceNum(parallel);
        context.getSessionVariable().setPipelineDop(1);
        
        context.getSessionVariable().setEnablePipelineEngine(false);
        context.setCluster(SystemInfoService.DEFAULT_CLUSTER);
        context.setDatabase(Constants.StatisticsDBName);
        context.setCatalog(GlobalStateMgr.getCurrentState());
        context.setCurrentUserIdentity(UserIdentity.ROOT);
        context.setQualifiedUser(UserIdentity.ROOT.getQualifiedUser());
        context.setQueryId(UUIDUtil.genUUID());
        context.setExecutionId(UUIDUtil.toTUniqueId(context.getQueryId()));
        context.setThreadLocalInfo();
        context.setStartTime();
        return context;
    }
Code review comment: Good point, we have to ensure current hosts have 0, 1, 2 or find another way to decide indices. Will look into it.

Code under review:
List<Integer> provisionIndices(int count) {
        if (count == 0) return List.of();
        NodeType hostType = requestedNodes.type().hostType();

        
        if (hostType == NodeType.host) return nodeRepository.database().readProvisionIndices(count);

        
        int offset = 1;
        Set<Integer> currentIndices = allNodes.nodeType(hostType)
                                              .stream()
                                              .map(node -> node.allocation().get().membership().index())
                                              .map(index -> index + offset)
                                              .collect(Collectors.toSet());
        List<Integer> indices = new ArrayList<>(count);
        for (int i = offset; indices.size() < count; i++) {
            if (!currentIndices.contains(i)) {
                indices.add(i);
            }
        }
        return indices;
    }

Line commented on: Set<Integer> currentIndices = allNodes.nodeType(hostType)

Revised code:
List<Integer> provisionIndices(int count) {
        if (count < 1) throw new IllegalArgumentException("Count must be positive");
        NodeType hostType = requestedNodes.type().hostType();

        
        if (hostType == NodeType.host) return nodeRepository.database().readProvisionIndices(count);

        
        Set<Integer> currentIndices = allNodes.nodeType(hostType)
                                              .stream()
                                              .map(Node::hostname)
                                              
                                              
                                              
                                              .map(NodeAllocation::parseIndex)
                                              .collect(Collectors.toSet());
        List<Integer> indices = new ArrayList<>(count);
        for (int i = 1; indices.size() < count; i++) {
            if (!currentIndices.contains(i)) {
                indices.add(i);
            }
        }
        return indices;
    }
Code review comment: Drawback of removing such timeout is, that if there are multiple deadlocks in single azure build, test level timeout would show all of them. Azure level would show just the first one. Secondly won't the Azure level timeout would take longer to kick in?  I'm not saying I'm strictly against removing it. But I'm just pointing this out. Having test level timeout is also sometimes annoying during debugging, so all in all I'm +/- 0 for this change.

Code under review:
protected File execute(UnalignedSettings settings) throws Exception {
		final File checkpointDir = temp.newFolder();
		StreamExecutionEnvironment env = settings.createEnvironment(checkpointDir);

		int minCheckpoints = 10;
		settings.dagCreator.accept(env, minCheckpoints, settings.slotSharing);
		try {
			final JobExecutionResult result = env.execute();

			collector.checkThat("NUM_OUT_OF_ORDER", result.<Long>getAccumulatorResult(NUM_OUT_OF_ORDER), equalTo(0L));
			collector.checkThat("NUM_DUPLICATES", result.<Long>getAccumulatorResult(NUM_DUPLICATES), equalTo(0L));
			collector.checkThat("NUM_LOST", result.<Long>getAccumulatorResult(NUM_LOST), equalTo(0L));
			collector.checkThat("NUM_FAILURES", result.<Integer>getAccumulatorResult(NUM_FAILURES), equalTo(settings.expectedFailures));
		} catch (Exception e) {
			if (settings.generateCheckpoint) {
				return Files.find(checkpointDir.toPath(), 2, (file, attr) -> attr.isDirectory() && file.getFileName().toString().startsWith("chk"))
					.findFirst()
					.map(Path::toFile)
					.orElseThrow(() -> new IllegalStateException("Cannot generate checkpoint", e));
			}
			throw e;
		}
		if (settings.generateCheckpoint) {
			fail("Could not generate checkpoint");
		}
		return null;
	}

Line commented on: final File checkpointDir = temp.newFolder();

Revised code:
protected File execute(UnalignedSettings settings) throws Exception {
		final File checkpointDir = temp.newFolder();
		StreamExecutionEnvironment env = settings.createEnvironment(checkpointDir);

		settings.dagCreator.create(env, settings.minCheckpoints, settings.slotSharing, settings.expectedFailures - 1);
		try {
			final JobExecutionResult result = env.execute();

			collector.checkThat("NUM_OUT_OF_ORDER", result.<Long>getAccumulatorResult(NUM_OUT_OF_ORDER), equalTo(0L));
			collector.checkThat("NUM_DUPLICATES", result.<Long>getAccumulatorResult(NUM_DUPLICATES), equalTo(0L));
			collector.checkThat("NUM_LOST", result.<Long>getAccumulatorResult(NUM_LOST), equalTo(0L));
			collector.checkThat("NUM_FAILURES", result.<Integer>getAccumulatorResult(NUM_FAILURES), equalTo(settings.expectedFailures));
		} catch (Exception e) {
			if (settings.generateCheckpoint) {
				return Files.find(checkpointDir.toPath(), 2, (file, attr) -> attr.isDirectory() && file.getFileName().toString().startsWith("chk"))
					.findFirst()
					.map(Path::toFile)
					.orElseThrow(() -> new IllegalStateException("Cannot generate checkpoint", e));
			}
			throw e;
		}
		if (settings.generateCheckpoint) {
			fail("Could not generate checkpoint");
		}
		return null;
	}
Code review comment: oops, I was about to start an even hackier approach here then I realised I could just use the platform CL as the parent..

Code under review:
public Enumeration<URL> getResources(String nm) throws IOException {
        ClassLoaderState state = getState();
        String name = sanitizeName(nm);
        
        
        boolean banned = state.bannedResources.contains(name);
        Set<URL> resources = new LinkedHashSet<>();
        
        
        
        
        
        

        
        
        
        
        
        
        
        
        if (name.startsWith(META_INF_SERVICES)) {
            try {
                Class<?> c = loadClass(name.substring(META_INF_SERVICES.length()));
                if (c.getClassLoader() == this) {
                    
                    
                    banned = true;
                }
            } catch (ClassNotFoundException ignored) {
                
            }
            
            
        }
        for (ClassPathElement i : elements) {
            ClassPathResource res = i.getResource(nm);
            if (res != null) {
                resources.add(res.getUrl());
            }
        }
        if (!banned) {
            if (resources.isEmpty() || aggregateParentResources) {
                Enumeration<URL> res = parent.getResources(nm);
                while (res.hasMoreElements()) {
                    resources.add(res.nextElement());
                }
            }
        }
        return Collections.enumeration(resources);
    }


Revised code:
public Enumeration<URL> getResources(String nm) throws IOException {
        ClassLoaderState state = getState();
        String name = sanitizeName(nm);
        
        
        boolean banned = state.bannedResources.contains(name);
        Set<URL> resources = new LinkedHashSet<>();
        
        
        
        
        
        

        
        
        
        
        
        
        
        
        if (name.startsWith(META_INF_SERVICES)) {
            try {
                Class<?> c = loadClass(name.substring(META_INF_SERVICES.length()));
                if (c.getClassLoader() == this) {
                    
                    
                    banned = true;
                }
            } catch (ClassNotFoundException ignored) {
                
            }
        }
        for (ClassPathElement i : elements) {
            ClassPathResource res = i.getResource(nm);
            if (res != null) {
                resources.add(res.getUrl());
            }
        }
        if (!banned) {
            if (resources.isEmpty() || aggregateParentResources) {
                Enumeration<URL> res = parent.getResources(nm);
                while (res.hasMoreElements()) {
                    resources.add(res.nextElement());
                }
            }
        }
        return Collections.enumeration(resources);
    }
Code review comment: Assuming the ULR goes green, I think this piece can be omitted. This got pulled in but is not really related.

Code under review:
new TransformTranslator<CombineGroupedValues>() {
          @Override
          public void translate(CombineGroupedValues transform, TranslationContext context) {
            translateHelper(transform, context);
          }

          private <K, InputT, OutputT> void translateHelper(
              final CombineGroupedValues<K, InputT, OutputT> primitiveTransform,
              TranslationContext context) {
            Combine.GroupedValues<K, InputT, OutputT> originalTransform =
                primitiveTransform.getOriginalCombine();
            StepTranslationContext stepContext =
                context.addStep(primitiveTransform, "CombineValues");
            translateInputs(
                stepContext,
                context.getInput(primitiveTransform),
                originalTransform.getSideInputs(),
                context);

            AppliedCombineFn<? super K, ? super InputT, ?, OutputT> fn =
                originalTransform.getAppliedFn(
                    context.getInput(primitiveTransform).getPipeline().getCoderRegistry(),
                    context.getInput(primitiveTransform).getCoder(),
                    context.getInput(primitiveTransform).getWindowingStrategy());

            stepContext.addEncodingInput(fn.getAccumulatorCoder());

            List<String> experiments = context.getPipelineOptions().getExperiments();
            boolean isFnApi = experiments != null && experiments.contains("beam_fn_api");

            if (isFnApi) {
              String ptransformId =
                  context.getSdkComponents().getPTransformIdOrThrow(context.getCurrentParent());
              stepContext.addInput(PropertyNames.SERIALIZED_FN, ptransformId);
            } else {
              stepContext.addInput(
                  PropertyNames.SERIALIZED_FN, byteArrayToJsonString(serializeToByteArray(fn)));
            }

            stepContext.addOutput(PropertyNames.OUTPUT, context.getOutput(primitiveTransform));
          }
        });

Line commented on: List<String> experiments = context.getPipelineOptions().getExperiments();

Revised code:
Override
          public void translate(CombineGroupedValues transform, TranslationContext context) {
            translateHelper(transform, context);
          }
Code review comment: Maybe better `"Problem deleting table " + table + ": " + e` for consistency. don't forget to propragate the original Exception too `Exception("Problem....", e);`

Code under review:
public void tearDown() throws Exception {
    try {
      helper.dropHiveTable(tableName);
    } catch (Exception e) {
      helper.closeConnection();
      throw new Exception("Problem with deleting database.");
    } finally {
      helper.closeConnection();
    }
  }

Line commented on: throw new Exception("Problem with deleting database.");

Revised code:
public void tearDown() throws Exception {
    try {
      helper.dropHiveTable(tableName);
    } catch (Exception e) {
      helper.closeConnection();
      throw new Exception("Problem with deleting table " + tableName + ": " + e, e);
    } finally {
      helper.closeConnection();
    }
  }
Code review comment: Do you have a test that peeks the next sequence number?

Code under review:
void peekOneMessage() {
        
        final int numberOfEvents = 1;
        when(managementNode.peek())
            .thenReturn(Mono.just(mock(ServiceBusReceivedMessage.class)));

        
        StepVerifier.create(consumer.peek())
            .expectNextCount(numberOfEvents)
            .verifyComplete();

    }

Line commented on: StepVerifier.create(consumer.peek())

Revised code:
void peekOneMessage() {
        
        final int numberOfEvents = 1;
        when(managementNode.peek())
            .thenReturn(just(mock(ServiceBusReceivedMessage.class)));

        
        StepVerifier.create(consumer.peek())
            .expectNextCount(numberOfEvents)
            .verifyComplete();

    }
Code review comment: We're in the `single` branch: we shouldn't split, no?

Code under review:
public Object getQueryParameter(String name, boolean single, boolean encoded, String separator) {
        if (single) {
            String val = serverRequest().getQueryParam(name);
            if (encoded && val != null) {
                val = Encode.encodeQueryParam(val);
            }

            if (separator != null) {
                String[] parts = val.split(separator);
                return new ArrayList<>(Arrays.asList(parts));
            } else {
                return val;
            }
        }

        
        List<String> strings = serverRequest().getAllQueryParams(name);
        if (encoded) {
            List<String> newStrings = new ArrayList<>();
            for (String i : strings) {
                newStrings.add(Encode.encodeQueryParam(i));
            }
            strings = newStrings;
        }

        if (separator != null) {
            List<String> result = new ArrayList<>(strings.size());
            for (int i = 0; i < strings.size(); i++) {
                String[] parts = strings.get(i).split(separator);
                result.addAll(Arrays.asList(parts));
            }
            return result;
        } else {
            return strings;
        }
    }

Line commented on: return new ArrayList<>(Arrays.asList(parts));

Revised code:
public Object getQueryParameter(String name, boolean single, boolean encoded, String separator) {
        if (single) {
            String val = serverRequest().getQueryParam(name);
            if (encoded && val != null) {
                val = Encode.encodeQueryParam(val);
            }
            return val;
        }

        
        List<String> strings = serverRequest().getAllQueryParams(name);
        if (encoded) {
            List<String> newStrings = new ArrayList<>();
            for (String i : strings) {
                newStrings.add(Encode.encodeQueryParam(i));
            }
            strings = newStrings;
        }

        if (separator != null) {
            List<String> result = new ArrayList<>(strings.size());
            for (int i = 0; i < strings.size(); i++) {
                String[] parts = strings.get(i).split(separator);
                result.addAll(Arrays.asList(parts));
            }
            return result;
        } else {
            return strings;
        }
    }
Code review comment: If only managed beans are supported then you should filter out unsupported bean types, i.e. `beanDiscoveryFinished.geBeans().stream().filter(BeanInfo::isClassBean)`.

Code under review:
private Optional<DotName> findCacheKeyGenerator(AnnotationInstance binding, AnnotationTarget target) {
        if (target.kind() == METHOD && (CACHE_RESULT.equals(binding.name()) || CACHE_INVALIDATE.equals(binding.name()))) {
            AnnotationValue keyGenerator = binding.value("keyGenerator");
            if (keyGenerator != null) {
                return Optional.of(keyGenerator.asClass().name());
            }
        }
        return Optional.empty();
    }

Line commented on: return Optional.empty();

Revised code:
private Optional<DotName> findCacheKeyGenerator(AnnotationInstance binding, AnnotationTarget target) {
        if (target.kind() == METHOD && (CACHE_RESULT.equals(binding.name()) || CACHE_INVALIDATE.equals(binding.name()))) {
            AnnotationValue keyGenerator = binding.value("keyGenerator");
            if (keyGenerator != null) {
                return Optional.of(keyGenerator.asClass().name());
            }
        }
        return Optional.empty();
    }
Code review comment: Actually previously it was possible for the `typeCastParamNode.type()` to be null. However, it was handled inside the `formatNode` method accordingly.  ```java private <T extends Node> T formatNode(T node, int trailingWS, int trailingNL) {         if (node == null || node.isMissing()) {             return node;         }        // ... } ```

Code under review:
public TypeCastParamNode transform(TypeCastParamNode typeCastParamNode) {
        NodeList<AnnotationNode> annotations = formatNodeList(typeCastParamNode.annotations(), 0, 1, 1, 0);
        Node type = formatNode(typeCastParamNode.type().orElse(null), env.trailingWS, env.trailingNL);

        return typeCastParamNode.modify()
                .withAnnotations(annotations)
                .withType(type)
                .apply();
    }

Line commented on: Node type = formatNode(typeCastParamNode.type().orElse(null), env.trailingWS, env.trailingNL);

Revised code:
public TypeCastParamNode transform(TypeCastParamNode typeCastParamNode) {
        NodeList<AnnotationNode> annotations = formatNodeList(typeCastParamNode.annotations(), 0, 1, 1, 0);
        Node type = formatNode(typeCastParamNode.type().orElse(null), env.trailingWS, env.trailingNL);

        return typeCastParamNode.modify()
                .withAnnotations(annotations)
                .withType(type)
                .apply();
    }
Code review comment: Yes, it would be more complicated to make this a managed context. Honestly, this context is not supposed to be used in production ;-).

Code under review:
public ContextState getState() {
        return new ContextState() {

            @Override
            public Map<InjectableBean<?>, Object> getContextualInstances() {
                HttpServletRequest httpServletRequest = servletRequest();
                if (httpServletRequest != null) {
                    return HttpSessionContext.this.getContextualInstances(httpServletRequest).getPresentValues().stream()
                            .collect(Collectors.toMap(ContextInstanceHandle::getBean, ContextInstanceHandle::get));
                }
                return Collections.emptyMap();
            }
        };
    }

Line commented on: HttpServletRequest httpServletRequest = servletRequest();

Revised code:
public ContextState getState() {
        return new ContextState() {

            @Override
            public Map<InjectableBean<?>, Object> getContextualInstances() {
                HttpServletRequest httpServletRequest = servletRequest();
                if (httpServletRequest != null) {
                    return HttpSessionContext.this.getContextualInstances(httpServletRequest).getPresentValues().stream()
                            .collect(Collectors.toMap(ContextInstanceHandle::getBean, ContextInstanceHandle::get));
                }
                return Collections.emptyMap();
            }
        };
    }
Code review comment: Yeah, if we need to separate streaming and store-only, we need it.

Code under review:
public List<NewDocumentType> getDocumentTypesWithIndexedCluster() {
        List<NewDocumentType> indexedDocTypes = new ArrayList<>();
        for (NewDocumentType type : documentDefinitions.values()) {
            if (findStreamingCluster(type.getFullName().getName()).isEmpty()
                    && hasIndexedCluster()
                    && getIndexed().hasDocumentDB(type.getFullName().getName())) {
                indexedDocTypes.add(type);
            }
        }
        return indexedDocTypes;
    }

Line commented on: if (findStreamingCluster(type.getFullName().getName()).isEmpty()

Revised code:
public List<NewDocumentType> getDocumentTypesWithIndexedCluster() {
        List<NewDocumentType> indexedDocTypes = new ArrayList<>();
        for (NewDocumentType type : documentDefinitions.values()) {
            if (findStreamingCluster(type.getFullName().getName()).isEmpty()
                    && hasIndexedCluster()
                    && getIndexed().hasDocumentDB(type.getFullName().getName())) {
                indexedDocTypes.add(type);
            }
        }
        return indexedDocTypes;
    }
Code review comment: If row neither of type **RowData** nor **String**，what to do here?

Code under review:
private void addBatch(T row) {
        if (row instanceof RowData) {
            RowData rowData = (RowData) row;
            Map<String, String> valueMap = new HashMap<>();
            StringJoiner value = new StringJoiner(this.fieldDelimiter);
            for (int i = 0; i < rowData.getArity() && i < fieldGetters.length; ++i) {
                Object field = fieldGetters[i].getFieldOrNull(rowData);
                if (jsonFormat) {
                    String data = field != null ? field.toString() : null;
                    valueMap.put(this.fieldNames[i], data);
                } else {
                    String data = field != null ? field.toString() : NULL_VALUE;
                    value.add(data);
                }
            }
            Object data = jsonFormat ? valueMap : value.toString();
            batch.add(data);

        }
        if (row instanceof String) {
            batch.add(row);
        }
    }

Line commented on: batch.add(row);

Revised code:
private void addBatch(T row) {
        if (row instanceof RowData) {
            RowData rowData = (RowData) row;
            Map<String, String> valueMap = new HashMap<>();
            StringJoiner value = new StringJoiner(this.fieldDelimiter);
            for (int i = 0; i < rowData.getArity() && i < fieldGetters.length; ++i) {
                Object field = fieldGetters[i].getFieldOrNull(rowData);
                if (jsonFormat) {
                    String data = field != null ? field.toString() : null;
                    valueMap.put(this.fieldNames[i], data);
                } else {
                    String data = field != null ? field.toString() : NULL_VALUE;
                    value.add(data);
                }
            }
            Object data = jsonFormat ? valueMap : value.toString();
            batch.add(data);

        } else if (row instanceof String) {
            batch.add(row);
        } else {
            throw new RuntimeException("The type of element should be 'RowData' or 'String' only.");
        }
    }
Code review comment: 👍 - this is good as the message is clear about what went wrong.

Code under review:
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
        final UrlBuilder urlBuilder = UrlBuilder.parse(context.getHttpRequest().getUrl());
        if (overwrite || urlBuilder.getPort() == null) {
            logger.info("Changing port to {}", port);

            try {
                context.getHttpRequest().setUrl(urlBuilder.setPort(port).toURL());
            } catch (MalformedURLException e) {
                return Mono.error(new RuntimeException(
                    String.format("Failed to set port %d to http request.", port), e));
            }
        }
        return next.process();
    }

Line commented on: String.format("Failed to set port %d to http request.", port), e));

Revised code:
public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) {
        final UrlBuilder urlBuilder = UrlBuilder.parse(context.getHttpRequest().getUrl());
        if (overwrite || urlBuilder.getPort() == null) {
            logger.info("Changing port to {}", port);

            try {
                context.getHttpRequest().setUrl(urlBuilder.setPort(port).toURL());
            } catch (MalformedURLException e) {
                return Mono.error(new RuntimeException(
                    String.format("Failed to set the HTTP request port to %d.", port), e));
            }
        }
        return next.process();
    }
Code review comment: Let's plug this hole now, and then do it properly. It may be some work.

Code under review:
private PrepareResult deploy(File applicationPackage, PrepareParams prepareParams, DeployHandlerLogger logger) {
        ApplicationId applicationId = prepareParams.getApplicationId();
        long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationPackage);
        Deployment deployment = prepare(sessionId, prepareParams, logger);

        if (deployment.configChangeActions().getRefeedActions().getEntries().stream().anyMatch(entry -> ! entry.allowed()))
            logger.log(Level.WARNING, "Activation rejected because of disallowed re-feed actions");
        else if (deployment.configChangeActions().getReindexActions().getEntries().stream().anyMatch(entry -> ! entry.allowed()))
            logger.log(Level.WARNING, "Activation rejected because of disallowed re-index actions");
        else
            deployment.activate();

        return new PrepareResult(sessionId, deployment.configChangeActions(), logger);
    }

Line commented on: if (deployment.configChangeActions().getRefeedActions().getEntries().stream().anyMatch(entry -> ! entry.allowed()))

Revised code:
private PrepareResult deploy(File applicationPackage, PrepareParams prepareParams, DeployHandlerLogger logger) {
        ApplicationId applicationId = prepareParams.getApplicationId();
        long sessionId = createSession(applicationId, prepareParams.getTimeoutBudget(), applicationPackage);
        Deployment deployment = prepare(sessionId, prepareParams, logger);

        if (deployment.configChangeActions().getRefeedActions().getEntries().stream().anyMatch(entry -> ! entry.allowed()))
            logger.log(Level.WARNING, "Activation rejected because of disallowed re-feed actions");
        else if (deployment.configChangeActions().getReindexActions().getEntries().stream().anyMatch(entry -> ! entry.allowed()))
            logger.log(Level.WARNING, "Activation rejected because of disallowed re-index actions");
        else
            deployment.activate();

        return new PrepareResult(sessionId, deployment.configChangeActions(), logger);
    }
Code review comment: NOTE: Overrides the client assertion at per request level.

Code under review:
public Mono<AccessToken> authenticateWithConfidentialClient(TokenRequestContext request) {
        return confidentialClientApplicationAccessor.getValue()
            .flatMap(confidentialClient -> Mono.fromFuture(() -> {
                ClientCredentialParameters.ClientCredentialParametersBuilder builder =
                    ClientCredentialParameters.builder(new HashSet<>(request.getScopes()))
                        .tenant(IdentityUtil
                            .resolveTenantId(tenantId, request, options));
                if (clientAssertionSupplier != null) {
                    builder.clientCredential(ClientCredentialFactory
                        .createFromClientAssertion(clientAssertionSupplier.get()));
                }
                return confidentialClient.acquireToken(builder.build());
            }
        )).map(MsalToken::new);
    }

Line commented on: if (clientAssertionSupplier != null) {

Revised code:
public Mono<AccessToken> authenticateWithConfidentialClient(TokenRequestContext request) {
        return confidentialClientApplicationAccessor.getValue()
            .flatMap(confidentialClient -> Mono.fromFuture(() -> {
                ClientCredentialParameters.ClientCredentialParametersBuilder builder =
                    ClientCredentialParameters.builder(new HashSet<>(request.getScopes()))
                        .tenant(IdentityUtil
                            .resolveTenantId(tenantId, request, options));
                if (clientAssertionSupplier != null) {
                    builder.clientCredential(ClientCredentialFactory
                        .createFromClientAssertion(clientAssertionSupplier.get()));
                }
                return confidentialClient.acquireToken(builder.build());
            }
        )).map(MsalToken::new);
    }
Code review comment: Every write will touch the last segment. The previous data is on disk, and the last data is in memory. Each write is append written at the end of InMemoryBuffer.

Code under review:
public boolean write(BaseRow row) throws IOException {
			try {
				this.serializer.serializeToPages(row, this.recordCollector);
				currentDataBufferOffset = this.recordCollector.getCurrentOffset();
				numBytesInLastBuffer = this.recordCollector.getCurrentPositionInSegment();
				recordCount++;

				for (BufferIterator iterator : iterators) {
					iterator.recordBuffer.updateLimitInLastSegment(numBytesInLastBuffer);
				}

				return true;
			} catch (EOFException e) {
				return false;
			}
		}

Line commented on: iterator.recordBuffer.updateLimitInLastSegment(numBytesInLastBuffer);

Revised code:
public boolean write(BaseRow row) throws IOException {
			try {
				this.serializer.serializeToPages(row, this.recordCollector);
				currentDataBufferOffset = this.recordCollector.getCurrentOffset();
				numBytesInLastBuffer = this.recordCollector.getCurrentPositionInSegment();
				recordCount++;
				return true;
			} catch (EOFException e) {
				return false;
			}
		}
Code review comment: ah. hmm...  Let's say that an exception occurs when retrieving the value from RocksDB. How likely is it that this exception happens again? I.e. how reliable are failure-cases? Currently, if there is any intermittent failure the metric is disabled forever.  If this is more of an all-or-nothing kind of thing we could try it out once before registering the metric and skipping the registration if it fails, and only skip repeated logging in the metric.

Code under review:
private void setProperty(ColumnFamilyHandle handle, String property, RocksDBNativeMetricView metricView) {
		if (metricView.isClosed()) {
			return;
		}
		try {
			synchronized (lock) {
				if (rocksDB != null) {
					long value = rocksDB.getLongProperty(handle, property);
					metricView.setValue(value);
				}
			}
		} catch (RocksDBException e) {
			metricView.close();
			LOG.warn("Failed to read native metric %s from RocksDB", property, e);
		}
	}

Line commented on: if (metricView.isClosed()) {

Revised code:
private void setProperty(ColumnFamilyHandle handle, String property, RocksDBNativeMetricView metricView) {
		if (metricView.isClosed()) {
			return;
		}
		try {
			synchronized (lock) {
				if (rocksDB != null) {
					long value = rocksDB.getLongProperty(handle, property);
					metricView.setValue(value);
				}
			}
		} catch (RocksDBException e) {
			metricView.close();
			LOG.warn("Failed to read native metric %s from RocksDB", property, e);
		}
	}
Code review comment: Are there other considerations here? In fact, there is no need to restart fe by dynamically loading the custom jar.

Code under review:
protected void setProperties(Map<String, String> properties) throws DdlException {
        Preconditions.checkNotNull(properties, "Properties of iceberg resource is null!");

        catalogType = properties.get(ICEBERG_CATALOG);
        if (StringUtils.isBlank(catalogType)) {
            throw new DdlException(ICEBERG_CATALOG + " must be set in properties");
        }

        switch (IcebergCatalogType.fromString(catalogType)) {
            case HIVE_CATALOG:
                metastoreURIs = properties.get(ICEBERG_METASTORE_URIS);
                if (StringUtils.isBlank(metastoreURIs)) {
                    throw new DdlException(ICEBERG_METASTORE_URIS + " must be set in properties");
                }
                break;
            case CUSTOM_CATALOG:
                catalogImpl = properties.get(ICEBERG_IMPL);
                if (StringUtils.isBlank(catalogImpl)) {
                    throw new DdlException(ICEBERG_IMPL + " must be set in properties");
                }
                try {
                    Thread.currentThread().getContextClassLoader().loadClass(catalogImpl);
                } catch (ClassNotFoundException e) {
                    throw new DdlException("Unknown class: " + catalogImpl);
                }
                break;
            default:
                throw new DdlException("Unexpected catalog type: " + catalogType);
        }
    }

Line commented on: Thread.currentThread().getContextClassLoader().loadClass(catalogImpl);

Revised code:
protected void setProperties(Map<String, String> properties) throws DdlException {
        Preconditions.checkNotNull(properties, "Properties of iceberg resource is null!");

        catalogType = properties.get(ICEBERG_CATALOG);
        if (StringUtils.isBlank(catalogType)) {
            throw new DdlException(ICEBERG_CATALOG + " must be set in properties");
        }

        switch (IcebergCatalogType.fromString(catalogType)) {
            case HIVE_CATALOG:
                metastoreURIs = properties.get(ICEBERG_METASTORE_URIS);
                if (StringUtils.isBlank(metastoreURIs)) {
                    throw new DdlException(ICEBERG_METASTORE_URIS + " must be set in properties");
                }
                break;
            case CUSTOM_CATALOG:
                catalogImpl = properties.get(ICEBERG_IMPL);
                if (StringUtils.isBlank(catalogImpl)) {
                    throw new DdlException(ICEBERG_IMPL + " must be set in properties");
                }
                try {
                    Thread.currentThread().getContextClassLoader().loadClass(catalogImpl);
                } catch (ClassNotFoundException e) {
                    throw new DdlException("Unknown class: " + catalogImpl);
                }
                break;
            default:
                throw new DdlException("Unexpected catalog type: " + catalogType);
        }
    }
Code review comment: Any reason not to us ByteString.copyFrom here?

Code under review:
public ByteString consumePrefixToByteString(int prefixSize) {
    ByteString rval;
    Preconditions.checkArgument(prefixSize <= size());
    if (prefixSize == size()) {
      return toByteStringAndReset();
    }
    int bytesFromBuffer = prefixSize - result.size();
    if (bytesFromBuffer == 0) {
      rval = result;
      result = ByteString.EMPTY;
      return rval;
    }
    if (bytesFromBuffer < 0) {
      rval = result.substring(0, prefixSize);
      result = result.substring(prefixSize);
      return rval;
    }
    
    if (shouldCopy(buffer.length, bytesFromBuffer)) {
      byte[] bufferCopy = new byte[bytesFromBuffer];
      System.arraycopy(buffer, 0, bufferCopy, 0, bytesFromBuffer);
      rval = result.concat(UnsafeByteOperations.unsafeWrap(bufferCopy));
    } else {
      rval = result.concat(UnsafeByteOperations.unsafeWrap(buffer, 0, bytesFromBuffer));
    }
    
    int remainingBytes = bufferPos - bytesFromBuffer;
    if (shouldCopy(buffer.length, remainingBytes)) {
      result = ByteString.copyFrom(buffer, bytesFromBuffer, remainingBytes);
    } else {
      result = UnsafeByteOperations.unsafeWrap(buffer, bytesFromBuffer, remainingBytes);
    }
    buffer = new byte[Math.min(Math.max(1, buffer.length), MAX_CHUNK_SIZE)];
    bufferPos = 0;
    return rval;
  }

Line commented on: rval = result.concat(UnsafeByteOperations.unsafeWrap(bufferCopy));

Revised code:
public ByteString consumePrefixToByteString(int prefixSize) {
    ByteString rval;
    Preconditions.checkArgument(prefixSize <= size());
    if (prefixSize == size()) {
      return toByteStringAndReset();
    }
    int bytesFromBuffer = prefixSize - result.size();
    if (bytesFromBuffer == 0) {
      rval = result;
      result = ByteString.EMPTY;
      return rval;
    }
    if (bytesFromBuffer < 0) {
      rval = result.substring(0, prefixSize);
      result = result.substring(prefixSize);
      return rval;
    }
    
    if (shouldCopy(buffer.length, bytesFromBuffer)) {
      rval = result.concat(ByteString.copyFrom(buffer, 0, bytesFromBuffer));
    } else {
      rval = result.concat(UnsafeByteOperations.unsafeWrap(buffer, 0, bytesFromBuffer));
    }
    
    int remainingBytes = bufferPos - bytesFromBuffer;
    if (shouldCopy(buffer.length, remainingBytes)) {
      result = ByteString.copyFrom(buffer, bytesFromBuffer, remainingBytes);
    } else {
      result = UnsafeByteOperations.unsafeWrap(buffer, bytesFromBuffer, remainingBytes);
    }
    buffer = new byte[Math.min(Math.max(1, buffer.length), MAX_CHUNK_SIZE)];
    bufferPos = 0;
    return rval;
  }