Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DR-3356] Ensure that ingests always exclusively lock the dataset when bulk mode is set to true #1539

Merged
merged 1 commit into from
Nov 15, 2023
Merged
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 @@ -142,7 +142,12 @@ public DatasetIngestFlight(FlightMap inputParameters, Object applicationContext)
.forEach(s -> this.addStep(s.step(), s.retryRule()));
}

addStep(new LockDatasetStep(datasetService, datasetId, true), lockDatasetRetry);
// Originally we didn't exclusively lock the dataset, the thinking being that there might
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the reasoning here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Of course! I want to be nicer to future us :)

// not be files as part of the ingest and ingesting files is what makes exclusive locking
// a requirement. However, if a user is specifying bulk ingest mode, it's fair to assume that
// files are included as part of the ingest and that will cause an exclusive lock.
boolean useSharedLock = !ingestRequestModel.isBulkMode();
addStep(new LockDatasetStep(datasetService, datasetId, useSharedLock), lockDatasetRetry);
boolean autocommit;
if (cloudPlatform.isGcp()) {
if (ingestRequestModel.getTransactionId() == null) {
Expand Down Expand Up @@ -301,7 +306,7 @@ public DatasetIngestFlight(FlightMap inputParameters, Object applicationContext)
randomBackoffRetry);
}
}
addStep(new UnlockDatasetStep(datasetService, datasetId, true), lockDatasetRetry);
addStep(new UnlockDatasetStep(datasetService, datasetId, useSharedLock), lockDatasetRetry);
addStep(
new JournalRecordUpdateEntryStep(
journalService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInRelativeOrder;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.params.provider.Arguments.arguments;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -108,21 +109,27 @@ void testDatasetIngestValidatesFileAccess(

LockDatasetStep lockDatasetStep =
FlightTestUtils.getStepWithClass(flight, LockDatasetStep.class);
assertThat(
flightDescription + " obtains shared dataset lock",
lockDatasetStep.isSharedLock(),
is(true));
assertThat(
flightDescription + " does not suppress 'dataset not found' exceptions",
if (bulkMode) {
assertFalse(
lockDatasetStep.isSharedLock(), flightDescription + " obtains exclusive dataset lock");
} else {
assertTrue(
lockDatasetStep.isSharedLock(), flightDescription + " obtains shared dataset lock");
}

assertFalse(
lockDatasetStep.shouldSuppressNotFoundException(),
is(false));
flightDescription + " does not suppress 'dataset not found' exceptions");

UnlockDatasetStep unlockDatasetStep =
FlightTestUtils.getStepWithClass(flight, UnlockDatasetStep.class);
assertThat(
flightDescription + " removes shared dataset lock",
unlockDatasetStep.isSharedLock(),
is(true));
if (bulkMode) {
assertFalse(
unlockDatasetStep.isSharedLock(), flightDescription + " removes exclusive dataset lock");
} else {
assertTrue(
unlockDatasetStep.isSharedLock(), flightDescription + " removes shared dataset lock");
}

if (jsonTypeIngest) {
// CSV ingests can only be run for metadata, not files
Expand Down