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

Use lock in FileSystems to allow only one thread to update options #34007

Closed
wants to merge 1 commit into from
Closed
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 @@ -85,6 +85,8 @@ public class FileSystems {
private static final AtomicReference<Map<String, FileSystem>> SCHEME_TO_FILESYSTEM =
new AtomicReference<>(ImmutableMap.of(DEFAULT_SCHEME, new LocalFileSystem()));

private static final Object lock = new Object();

/** ******************************** METHODS FOR CLIENT ********************************* */

/** Checks whether the given spec contains a glob wildcard character. */
Expand Down Expand Up @@ -586,15 +588,17 @@ public static void setDefaultPipelineOptions(PipelineOptions options) {
return;
}

if (FILESYSTEM_REVISION.compareAndSet(revision, KV.of(id, nextRevision))) {
Set<FileSystemRegistrar> registrars =
Sets.newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE);
registrars.addAll(
Lists.newArrayList(
ServiceLoader.load(FileSystemRegistrar.class, ReflectHelpers.findClassLoader())));

SCHEME_TO_FILESYSTEM.set(verifySchemesAreUnique(options, registrars));
return;
synchronized (lock) {
if (FILESYSTEM_REVISION.compareAndSet(revision, KV.of(id, nextRevision))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we get rid of the atomic filesystem revision if we're synchronizing? It's complicated to think through possible timings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kennknowles what do you think about this? is it safe to remove atomic from FILESYSTEM_REVISION?

Set<FileSystemRegistrar> registrars =
Sets.newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE);
registrars.addAll(
Lists.newArrayList(
ServiceLoader.load(FileSystemRegistrar.class, ReflectHelpers.findClassLoader())));

SCHEME_TO_FILESYSTEM.set(verifySchemesAreUnique(options, registrars));
return;
}
}
}
}
Expand Down
Loading