Skip to content

Conversation

QwertyManiac
Copy link
Contributor

  • Tests required log capture so the LOG variable was elevated in visibility, which required changes in a few test methods unrelated to just this change.
  • Timeout is applied to both, the regular groups and the partial group listing check commands.
  • Default is left to 0 to not break current behaviour (i.e. to wait forever until groups are resolvable).

@Override
public void setConf(Configuration conf) {
super.setConf(conf);
timeout = conf.getLong(
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 use Configuration#getTimeDuration() instead of Configuration#getLong to make the newly added configuration key easier to use?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in added commit.

} catch (PartialGroupNameException pge) {
LOG.warn("unable to return groups for user " + user, pge);
LOG.warn("unable to return groups for user {}", user, pge);
return new LinkedList<>();
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 use flyweight pattern to minimize memory usage for the empty LinkList?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in added commit.

Arrays.asList(executor.getExecString()),
timeout
);
return new LinkedList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

flyweight pattern applies here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in added commit.

- Shared the empty group list return objects
- Switched to use of getTimeDuration for the introduced config
- Changed the property name to reflect seconds (and removed a redundant word
public static final String HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT =
"hadoop.security.groups.shell.groups.command.timeout";
public static final String HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS =
"hadoop.security.groups.shell.command.timeout.secs";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep "hadoop.security.groups.shell.groups.command.timeout". Sorry I was not clear about this when suggesting Configuration#getTimeDuration. It allows admin to specify the time values with suffix like 10s, 1m, 2h. So the ."secs" won't be needed 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.

I'd just felt it would be clearer to have '.secs' in it indicating the minimum unit type despite the parser. I've removed that in the latest commit and added some examples into its doc-text in the xml.

LoggerFactory.getLogger(ShellBasedUnixGroupsMapping.class);

private long timeout = 0L;
private final List<String> emptyGroupsList = new LinkedList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be static.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in the latest commit.

- Removed 'secs' in config name and clarified examples in its docs
- Made empty groups list static
- Added a null guard in setConf for constructors that do not use ReflectionUtils to pass a valid config
ShellBasedUnixGroupsMapping.LOG);

private static final boolean WINDOWS =
(Shell.osType == Shell.OSType.OS_TYPE_WIN);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can just use Shell.WINDOWS instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, addressed in new commit.

message +=
" because of the command taking longer than " +
"the configured timeout: " + timeout + " seconds";
throw new PartialGroupNameException(message);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this line is not needed if it will throw the exception anyway? The only difference is that it will not carry the original exception

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, addressed in new commit. I just felt the timeout exception may look weird, but I've dropped the line so we can be consistent in exposing the exception at all times.

- Also did a few small cleanups
- Exposed the under-timeout stream error as a debug log, just in case its useful. Earlier change just hid it permanently
"command '{}' ran longer than the configured timeout limit of " +
"{} seconds.",
user,
Arrays.asList(executor.getExecString()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Reviewed the patch again, and I think it's almost ready.
Here's one nit regarding the warning message here: it would print something like "Unable to return groups for user 'foobarnonexistinguser' as shell group lookup command '[sleep, 2]'". But this can be confusing as the command is not run with brackets and comas.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am +1 pending this and Jenkins precommit build. Somehow Jenkins is never run for your patches.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you again @jojochuang. I've added a new change here addressing your comments. I've also uploaded the full patch directly to JIRA to trigger a build test.

- Instead of printing the command list form, print a readable form
- Uses Guava's Joiner over Java 8's native StringJoiner to ensure compat. with branch-2
@QwertyManiac
Copy link
Contributor Author

Done via e8694de.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants