ozone icon indicating copy to clipboard operation
ozone copied to clipboard

HDDS-10230. Preventing V3 Schema from Creating Container DB in the Wrong Location

Open xichen01 opened this issue 1 year ago • 1 comments

What changes were proposed in this pull request?

Preventing V3 Schema from Creating Container DB in the Wrong Location.

  • Currently, when the HddsVolume cannot load the "V3 Schema Container DB", it will create a "V3 Schema Container DB" in the logged-in user's home directory (dbOptions.setCreateIfMissing(true);). If there are multiple abnormal HddsVolume, all the Containers from these abnormal Volumes will using the same DB.
  • For HddsVolume that loads the Container DB abnormally, we should just make it a Failed Volume.

root cause

When the HddsVolume load "V3 Schema Container DB" abnormally, the containerData.getVolume().getDbParentDir() will be null. The

new File(containerData.getVolume().getDbParentDir(), OzoneConsts.CONTAINER_DB_NAME);

will be

new File(null, OzoneConsts.CONTAINER_DB_NAME);

then

new File(null, OzoneConsts.CONTAINER_DB_NAME).getAbsolutePath()

will return ${user.dir}/container.db

java.io.File#getAbsolutePath:

  /**
      ...
    * If this abstract pathname is the empty abstract pathname then
    * the pathname string of the current user directory, 
      ...
  **/
    public String getAbsolutePath() {
        return fs.resolve(this);
    }

KeyValueContainerLocationUtil#getContainerDBFile:

  public static File getContainerDBFile(KeyValueContainerData containerData) {
    if (containerData.hasSchema(OzoneConsts.SCHEMA_V3)) {
      return new File(containerData.getVolume().getDbParentDir(),
          OzoneConsts.CONTAINER_DB_NAME);
    }
    return getContainerDBFile(containerData.getMetadataPath(), containerData);
  }

What is the link to the Apache JIRA

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

How was this patch tested?

Unit Test

xichen01 avatar Jan 28 '24 12:01 xichen01

Thanks @xichen01 for working on this. There are some test failures:

https://github.com/xichen01/ozone/actions/runs/7685544604/job/20943567917#step:6:11

(TestOzoneContainerWithTLS also failed for me locally.)

adoroszlai avatar Jan 28 '24 12:01 adoroszlai

Thanks @xichen01 for the contribution.

ChenSammi avatar Apr 08 '24 07:04 ChenSammi