Skip to content

HDDS-11622. Support domain socket creation#7379

Closed
ChenSammi wants to merge 6 commits intoapache:masterfrom
ChenSammi:HDDS-11622
Closed

HDDS-11622. Support domain socket creation#7379
ChenSammi wants to merge 6 commits intoapache:masterfrom
ChenSammi:HDDS-11622

Conversation

@ChenSammi
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Implemented a factory to create DomainSocket.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-11622

How was this patch tested?

It will be tested in next patch.


public static final boolean OZONE_READ_SHORT_CIRCUIT_DEFAULT = false;
public static final String OZONE_DOMAIN_SOCKET_PATH = "ozone.domain.socket.path";
public static final String OZONE_DOMAIN_SOCKET_PATH_DEFAULT = "/var/lib/ozone/dn_socket";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we use existing directories like ozone.metadata.dirs or hdds.metadata.dir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

NO. This OZONE_DOMAIN_SOCKET_PATH_DEFAULT file will be created by DomainSocket process. It cannot be an existing file. Also Hadoop native library has different permission requirement on this path.

https://cwiki.apache.org/confluence/display/HADOOP2/SocketPathSecurity

type = ConfigType.SIZE,
description = "Buffer size of reader/writer.",
tags = { ConfigTag.CLIENT, ConfigTag.DATANODE })
private int shortCircuitBufferSize = 128 * 1024;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

HDFS has default short circuit buffer size of 1MB.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tested the different values. Bigger buffer size doesn't help to improve the performance.
The short-circuit channel only exchange getBlock request and response. The value is determined by how big will a request and a response of a 256MB block size, 4MB chunk size, 16KB checksum size block. The request is round 500 bytes, and the response is around
30 + 53 * 64 + 6 * 16384 ~ 100k
block size (exclude chunks) - 30 bytes
chunk size (one checksums) - 53 bytes
one checksum size - 6 bytes

// See #{java.org.apache.hadoop.net.unix.DomainSocket#validateSocketPathSecurity0}
// for details.
//
// So unless you are running as root or the hdfs superuser, you cannot
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// So unless you are running as root or the hdfs superuser, you cannot
// So unless you are running as root or the ozone superuser, you cannot

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the ozone superuser -> an ozone admin ?

Copy link
Copy Markdown
Contributor Author

@ChenSammi ChenSammi Oct 31, 2024

Choose a reason for hiding this comment

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

It means the user who launches the service.

Comment on lines +127 to +132
public static synchronized DomainSocketFactory getInstance(ConfigurationSource conf) {
if (instance == null) {
instance = new DomainSocketFactory(conf);
}
return instance;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static synchronized DomainSocketFactory getInstance(ConfigurationSource conf) {
if (instance == null) {
instance = new DomainSocketFactory(conf);
}
return instance;
}
public static DomainSocketFactory getInstance(ConfigurationSource conf) {
if (instance == null) {
synchronized (DomainSocketFactory.class) {
instance = new DomainSocketFactory(conf);
}
}
return instance;
}

Use double-checked locking instead: https://www.baeldung.com/java-singleton-double-checked-locking


public static final String FEATURE = "short-circuit reads";
public static final String FEATURE_FLAG = "SC";
private static boolean nativeCodeLoaded = false;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

May be better nativeLibraryLoaded instead of nativeCodeLoaded.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

make sense.

long startTime = System.nanoTime();
if (!shortCircuitEnabled) {
LOG.info(FEATURE + " is disabled.");
pathInfo = PathInfo.NOT_CONFIGURED;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can ignore putting in pathInfo and further into pathMap when shortCircuit is disabled, we can throw exception?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The DomainSocketFactory.java is an singleton instance. It is only instantiated once. Later reference will call isServiceEnabled and isServiceReady to determine whether DomainSocket can be created or not.

}

public static final String FEATURE = "short-circuit reads";
public static final String FEATURE_FLAG = "SC";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Unused FEATURE_FLAG

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It will be used in next patch.

Copy link
Copy Markdown
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

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

Do we plan to add tests around these new code?

We would also need to package libadhoop into Ozone, into Ozone's dev docker image, and add tests for that.

@ChenSammi
Copy link
Copy Markdown
Contributor Author

ChenSammi commented Nov 5, 2024

Do we plan to add tests around these new code?

We would also need to package libadhoop into Ozone, into Ozone's dev docker image, and add tests for that.

I separated the previous patch into sub patches, for easy review. The separation from an actually complete patch is a little time consuming. The tests will be added in later patches, which require more new logics to run together.

Copy link
Copy Markdown
Contributor

@ashishkumar50 ashishkumar50 left a comment

Choose a reason for hiding this comment

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

Thanks @ChenSammi for updating the patch, LGTM +1.

@ChenSammi
Copy link
Copy Markdown
Contributor Author

ChenSammi commented Nov 6, 2024

Thanks @jojochuang @smengcl @ashishkumar50 for the review. I will close this JIRA and provide a new one. I ment to push the patch to the feature branch HDDS-10685.

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.

4 participants