Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_API_SERVER_SERVICE_UNAVAILABLE_COUNT;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_API_SERVER_SIDE_ERROR_COUNT;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_API_SERVER_TIMEOUT_COUNT;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.WRITE_CHECKSUM_FAILURE_COUNT;
import static com.google.cloud.hadoop.gcsio.StatisticTypeEnum.TYPE_DURATION;
import static com.google.cloud.hadoop.gcsio.StatisticTypeEnum.TYPE_DURATION_TOTAL;
import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -303,6 +304,10 @@ void incrementGcsExceptionCount() {
increment(EXCEPTION_COUNT);
}

void incrementWriteChecksumFailureCount() {
increment(WRITE_CHECKSUM_FAILURE_COUNT);
}

void incrementGcsTotalRequestCount() {
increment(GCS_API_REQUEST_COUNT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics;
import com.google.cloud.hadoop.gcsio.StatisticTypeEnum;
import com.google.cloud.hadoop.util.GCSChecksumFailureEvent;
import com.google.cloud.hadoop.util.GcsJsonApiEvent;
import com.google.cloud.hadoop.util.GcsJsonApiEvent.EventType;
import com.google.cloud.hadoop.util.GcsJsonApiEvent.RequestType;
Expand Down Expand Up @@ -141,6 +142,11 @@ private void subscriberOnException(IOException exception) {
storageStatistics.incrementGcsExceptionCount();
}

@Subscribe
private void onGcsChecksumFailure(GCSChecksumFailureEvent exception) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The parameter name exception is a bit misleading here. Although GCSChecksumFailureEvent extends Exception, in this context, it's functioning as an event rather than a handled exception. Renaming it to event would improve code clarity and better reflect its purpose within the event bus system.

Suggested change
private void onGcsChecksumFailure(GCSChecksumFailureEvent exception) {
private void onGcsChecksumFailure(GCSChecksumFailureEvent event) {

storageStatistics.incrementWriteChecksumFailureCount();
}

/**
* Updating the required gcs specific statistics based on httpresponse.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_API_SERVER_SIDE_ERROR_COUNT;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_API_SERVER_TIMEOUT_COUNT;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.GCS_METADATA_REQUEST;
import static com.google.cloud.hadoop.gcsio.GoogleCloudStorageStatistics.WRITE_CHECKSUM_FAILURE_COUNT;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.hadoop.util.GcsJsonApiEvent;
Expand Down Expand Up @@ -184,6 +185,14 @@ public void gcs_clientBadRequestCount() throws IOException {
verifyStatistics(verifyCounterStats);
}

@Test
public void gcs_writeChecksumFailureCount() throws IOException {
GoogleCloudStorageEventBus.postWriteChecksumFailure();
GhfsGlobalStorageStatistics verifyCounterStats = new GhfsGlobalStorageStatistics();
verifyCounterStats.incrementCounter(WRITE_CHECKSUM_FAILURE_COUNT, 1);
verifyStatistics(verifyCounterStats);
}

private class TestGcsApiEvent implements IGcsJsonApiEvent {
private final int statusCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
/** Statistics which are collected in GCS Connector. */
public enum GoogleCloudStorageStatistics {
EXCEPTION_COUNT("exception_count", "Counts the number of exceptions encountered", TYPE_COUNTER),
WRITE_CHECKSUM_FAILURE_COUNT(
"write_checksum_failure_count",
"Counts the number of checksum failures during write",
TYPE_COUNTER),

/** Status Code Counters for JSON Path */
GCS_API_REQUEST_COUNT(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private void verifyChecksums(String serverProvidedCrc32c) throws IOException {
String srcCrc =
BaseEncoding.base64().encode(Ints.toByteArray(cumulativeCrc32cHasher.hash().asInt()));
if (!srcCrc.equals(serverProvidedCrc32c)) {
GoogleCloudStorageEventBus.postWriteChecksumFailure();
throw new IOException(
String.format(
"Data integrity check failed for resource '%s'. Client-calculated CRC32C (%s) did not match server-provided CRC32C (%s).",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2025 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.cloud.hadoop.util;

/** A thin class to emit checksum failure event for EventBus notification. */
public class GCSChecksumFailureEvent extends Exception {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve code robustness and clearly state its intent, this class should be declared as final. Since it serves as a simple marker event and is not designed for extension, making it final prevents subclassing.

Suggested change
public class GCSChecksumFailureEvent extends Exception {}
public final class GCSChecksumFailureEvent extends Exception {}

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class GoogleCloudStorageEventBus {
private static EventBus eventBus = new EventBus();

private static IOException exception = new IOException();
private static GCSChecksumFailureEvent checksumFailureEvent = new GCSChecksumFailureEvent();

/**
* Method to register an obj to event bus
Expand Down Expand Up @@ -76,4 +77,8 @@ public static void onGrpcStatus(Status status) {
public static void postGcsJsonApiEvent(IGcsJsonApiEvent gcsJsonApiEvent) {
eventBus.post(gcsJsonApiEvent);
}

public static void postWriteChecksumFailure() {
eventBus.post(checksumFailureEvent);
}
}