Skip to content

Fix some secondary/read-only DB logic - #13441

Closed
pdillinger wants to merge 3 commits into
meta:mainfrom
pdillinger:secondary_read_only_logic
Closed

pdillinger wants to merge 3 commits into
meta:mainfrom
pdillinger:secondary_read_only_logic

Conversation

@pdillinger

Copy link
Copy Markdown
Contributor

Summary:
Primarily, fix an issue from #13316 with opening secondary DB with preserve/preclude option (crash test disable in #13439). The issue comes down to mixed-up interpretations of "read_only" which should now be resolved. I've introduced the stronger notion of "unchanging" which means the VersionSet never sees any changes to the LSM tree, and the weaker notion of "read_only" which means LSM tree changes are not written through this VersionSet/etc. but can pick up externally written changes. In particular, ManifestTailer should use read_only=true (along with unchanging=false) for proper handling of preserve/preclude options.

A new assertion in VersionSet::CreateColumnFamily to help ensure sane usage of the two boolean flags is incompatible with the known wart of allowing CreateColumnFamily on a read-only DB. So to keep that assertion, I have fixed that issue by disallowing it. And this in turn required downstream clean-up in ldb, where I cleaned up some call sites as well.

Also, rename SanitizeOptions for ColumnFamilyOptions to SanitizeCfOptions, for ease of search etc.

Test Plan:

  • Added preserve option to a test in db_secondary_test, which reproduced the failure seen in the crash test.
  • Revert Temp disable in crash test: secondary instance + seqno-time tracking #13439 to re-enable crash test functionality
  • Update some tests to deal with disallowing CF creation on read-only DB
  • Add some testing around read-only DBs and CreateColumnFamily(ies)
  • Resurrect a nearby test for read-only DB to be sure it doesn't write to the DB dir. New EnforcedReadOnlyReopen should probably be used in more places but didn't want to attempt a big migration here and now. (Suggested follow-up.)

Summary:
Primarily, fix an issue from meta#13316 with opening secondary DB with
preserve/preclude option (crash test disable in meta#13439). The issue comes
down to mixed-up interpretations of "read_only" which should now be
resolved. I've introduced the stronger notion of "unchanging" which means
the VersionSet never sees any changes to the LSM tree, and the weaker
notion of "read_only" which means LSM tree changes are not written
through this VersionSet/etc. but can pick up externally written changes.
In particular, ManifestTailer should use read_only=true (along with
unchanging=false) for proper handling of preserve/preclude options.

A new assertion in VersionSet::CreateColumnFamily to help ensure sane
usage of the two boolean flags is incompatible with the known wart of
allowing CreateColumnFamily on a read-only DB. So to keep that
assertion, I have fixed that issue by disallowing it. And this in turn
required downstream clean-up in ldb, where I cleaned up some call sites
as well.

Also, rename SanitizeOptions for ColumnFamilyOptions to
SanitizeCfOptions, for ease of search etc.

Test Plan:
* Added preserve option to a test in db_secondary_test, which reproduced
  the failure seen in the crash test.
* Revert meta#13439 to re-enable crash test functionality
* Update some tests to deal with disallowing CF creation on read-only DB
* Add some testing around read-only DBs and CreateColumnFamily(ies)
* Resurrect a nearby test for read-only DB to be sure it doesn't write
  to the DB dir. New EnforcedReadOnlyReopen should probably be used in
  more places but didn't want to attempt a big migration here and now.
  (Suggested follow-up.)
@pdillinger

Copy link
Copy Markdown
Contributor Author

D70789444

@jowlyzhang jowlyzhang left a comment

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.

This is really hard to detangle, thank you for the improvement! I have some general questions.

Comment thread db/column_family.cc
ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
bool read_only,
const ColumnFamilyOptions& src) {
ColumnFamilyOptions SanitizeCfOptions(const ImmutableDBOptions& db_options,

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.

Thanks!

Comment thread tools/ldb_cmd.cc Outdated
const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags)
: LDBCommand(options, flags, false,
: LDBCommand(options, flags, false /* is_read_only */,

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.

Should this command be read only too?

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.

Good catch. I'll see if I can safely sneak that into this PR. (I'll double-check that there are sufficient existing unit tests.)

return Status::NotSupported("Not supported operation in read only mode.");
}

using DB::CreateColumnFamily;

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.

I guess drop column family doesn't affect the options sanitization, but if what we are going with unchanging is no LSM trees mutation across the DB, no manifest writes(usage of ReadOnlyFileSystem in test) , should we consider disabling user initiated dropping column family too? Are we considering as a follow up to disable these for DBImplSecondary too.

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.

Yes, drop column family should probably be disallowed also, but I didn't want to keep adding to the scope of this PR. :) I left the FIXME in place in db_impl_readonly.h which likely includes more remaining than just drop CF.

The story with secondary instance is more complex than I care to attempt to resolve at the moment. https://github.com/facebook/rocksdb/blob/04b53a2608d844d22f51de1f3f0c7c3d1c588ada/include/rocksdb/db.h#L316-L322

Comment thread tools/ldb_cmd.cc Outdated
const std::map<std::string, std::string>& options,
const std::vector<std::string>& flags)
: LDBCommand(options, flags, true, {ARG_DB}) {
: LDBCommand(options, flags, true /* is_read_only */, {ARG_DB}) {

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.

nit: If we decide to not allow read only DB drop column family, this command will need to open in non read only mode.

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.

Thanks. It shouldn't hurt to preemptively make this right, so I'll try that.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot

Copy link
Copy Markdown
Contributor

@pdillinger merged this pull request in b9c7481.

ybtsdst pushed a commit to ybtsdst/rocksdb that referenced this pull request Apr 27, 2025
Summary:
Primarily, fix an issue from meta#13316 with opening secondary DB with preserve/preclude option (crash test disable in meta#13439). The issue comes down to mixed-up interpretations of "read_only" which should now be resolved. I've introduced the stronger notion of "unchanging" which means the VersionSet never sees any changes to the LSM tree, and the weaker notion of "read_only" which means LSM tree changes are not written through this VersionSet/etc. but can pick up externally written changes. In particular, ManifestTailer should use read_only=true (along with unchanging=false) for proper handling of preserve/preclude options.

A new assertion in VersionSet::CreateColumnFamily to help ensure sane usage of the two boolean flags is incompatible with the known wart of allowing CreateColumnFamily on a read-only DB. So to keep that assertion, I have fixed that issue by disallowing it. And this in turn required downstream clean-up in ldb, where I cleaned up some call sites as well.

Also, rename SanitizeOptions for ColumnFamilyOptions to SanitizeCfOptions, for ease of search etc.

Pull Request resolved: meta#13441

Test Plan:
* Added preserve option to a test in db_secondary_test, which reproduced the failure seen in the crash test.
* Revert meta#13439 to re-enable crash test functionality
* Update some tests to deal with disallowing CF creation on read-only DB
* Add some testing around read-only DBs and CreateColumnFamily(ies)
* Resurrect a nearby test for read-only DB to be sure it doesn't write to the DB dir. New EnforcedReadOnlyReopen should probably be used in more places but didn't want to attempt a big migration here and now. (Suggested follow-up.)

Reviewed By: jowlyzhang

Differential Revision: D70808033

Pulled By: pdillinger

fbshipit-source-id: 486b4e9f9c9045150a0ebb9cb302753d03932a3f
SoujanyaPonnapalli pushed a commit to tyler-griggs/rocksdb that referenced this pull request Jul 20, 2025
Summary:
Primarily, fix an issue from meta#13316 with opening secondary DB with preserve/preclude option (crash test disable in meta#13439). The issue comes down to mixed-up interpretations of "read_only" which should now be resolved. I've introduced the stronger notion of "unchanging" which means the VersionSet never sees any changes to the LSM tree, and the weaker notion of "read_only" which means LSM tree changes are not written through this VersionSet/etc. but can pick up externally written changes. In particular, ManifestTailer should use read_only=true (along with unchanging=false) for proper handling of preserve/preclude options.

A new assertion in VersionSet::CreateColumnFamily to help ensure sane usage of the two boolean flags is incompatible with the known wart of allowing CreateColumnFamily on a read-only DB. So to keep that assertion, I have fixed that issue by disallowing it. And this in turn required downstream clean-up in ldb, where I cleaned up some call sites as well.

Also, rename SanitizeOptions for ColumnFamilyOptions to SanitizeCfOptions, for ease of search etc.

Pull Request resolved: meta#13441

Test Plan:
* Added preserve option to a test in db_secondary_test, which reproduced the failure seen in the crash test.
* Revert meta#13439 to re-enable crash test functionality
* Update some tests to deal with disallowing CF creation on read-only DB
* Add some testing around read-only DBs and CreateColumnFamily(ies)
* Resurrect a nearby test for read-only DB to be sure it doesn't write to the DB dir. New EnforcedReadOnlyReopen should probably be used in more places but didn't want to attempt a big migration here and now. (Suggested follow-up.)

Reviewed By: jowlyzhang

Differential Revision: D70808033

Pulled By: pdillinger

fbshipit-source-id: 486b4e9f9c9045150a0ebb9cb302753d03932a3f
Tim-Reed pushed a commit to Tim-Reed/rocksdb that referenced this pull request Oct 1, 2026
Summary:
Primarily, fix an issue from meta#13316 with opening secondary DB with preserve/preclude option (crash test disable in meta#13439). The issue comes down to mixed-up interpretations of "read_only" which should now be resolved. I've introduced the stronger notion of "unchanging" which means the VersionSet never sees any changes to the LSM tree, and the weaker notion of "read_only" which means LSM tree changes are not written through this VersionSet/etc. but can pick up externally written changes. In particular, ManifestTailer should use read_only=true (along with unchanging=false) for proper handling of preserve/preclude options.

A new assertion in VersionSet::CreateColumnFamily to help ensure sane usage of the two boolean flags is incompatible with the known wart of allowing CreateColumnFamily on a read-only DB. So to keep that assertion, I have fixed that issue by disallowing it. And this in turn required downstream clean-up in ldb, where I cleaned up some call sites as well.

Also, rename SanitizeOptions for ColumnFamilyOptions to SanitizeCfOptions, for ease of search etc.

Pull Request resolved: meta#13441

Test Plan:
* Added preserve option to a test in db_secondary_test, which reproduced the failure seen in the crash test.
* Revert meta#13439 to re-enable crash test functionality
* Update some tests to deal with disallowing CF creation on read-only DB
* Add some testing around read-only DBs and CreateColumnFamily(ies)
* Resurrect a nearby test for read-only DB to be sure it doesn't write to the DB dir. New EnforcedReadOnlyReopen should probably be used in more places but didn't want to attempt a big migration here and now. (Suggested follow-up.)

Reviewed By: jowlyzhang

Differential Revision: D70808033

Pulled By: pdillinger

fbshipit-source-id: 486b4e9f9c9045150a0ebb9cb302753d03932a3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants