Skip to content

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Nov 14, 2023

The change in dbSwapDatabases seems harmless. Because in non-clustered
mode, dbBuckets calculations are strictly accurate and in cluster mode,
we only have one DB. Modify it for uniformity (just like resize_cursor).

The change in swapMainDbWithTempDb is needed in case we swap with the
temp db, otherwise the overhead memory usage of db can be miscalculated.

In addition we will swap all fields (including rehashing list), just for
completeness (and reduce the chance of surprises in the future).

Introduced in #12697.

The change in dbSwapDatabases seems harmless. Because in non-clustered
mode, dbBuckets calculations are strictly accurate and in cluster mode,
we only have one DB. Modify it for uniformity (just like resize_cursor).

The change in swapMainDbWithTempDb is needed in case we swap with the
temp db, otherwise the overhead memory usage of db can be miscalculated.

Introduced in redis#12697.
@enjoy-binbin
Copy link
Contributor Author

should we also swap the rehashing?

Copy link
Contributor

@hpatro hpatro left a comment

Choose a reason for hiding this comment

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

bucket_count and rehashing are only used in cluster-enabled and it allows only one 1 db. If you see dictRehashingStarted, we do an early exit at the start of the method.

So, I believe this change is not required.

@soloestoy
Copy link
Contributor

Currently, it is indeed not necessary, but if unsharded-cluster needs to support multiple databases, then it would be required. However, unsharded-cluster also has many other tasks to accomplish.

@enjoy-binbin
Copy link
Contributor Author

enjoy-binbin commented Nov 15, 2023

yean, the changes is no needed indeed. since we also swap resize_cursor (it is also cluster only), i think it will be fine to do the swap, and in addition, i personally think that swapping is good in generally, although it only used in the cluster.

Let’s see the final decision of oran and soloestoy

Copy link
Contributor

@zuiderkwast zuiderkwast left a comment

Choose a reason for hiding this comment

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

I think it is good to merge this.

It's better not to rely on the two facts that bucket count is only used in cluster mode and that SWAPDB can't be used in cluster mode. This function can have less assumptions about the world if we just swap the bucket count too, like we swap everything else.

@oranagra
Copy link
Member

when cluster mode will support multiple dbs, it'll be unsharded. these two things go together. i.e. as soon as cluster is sharded, it has just one db.
so i don't see why this would be needed on a multiple db cluster, unless we some day find another use for this mechanism.

maybe it's easier to just place some comment that clarifies this var and other structures are only present when redis is sharded?
if / when we do that, we may need to modify other comments or conditions not to depend on "cluster mode" but rather on "sharding" or some other term.

@enjoy-binbin
Copy link
Contributor Author

in the original PR, we swapped everything, including resize_cursor (cluster only). do we still want to swap everything (dbDictState)?

otherwise let's close it.

@enjoy-binbin enjoy-binbin changed the title Swap bucket_count when swap the dbDict Swap everything when swap the dbDict Dec 7, 2023
@zuiderkwast
Copy link
Contributor

I think it's good to swap everything. The code doesn't have to rely on assumptions that certain features cannot be used together. Those assumptions add to the complexity. Better let the code just swap everything IMO. But I don't mind if we close it if others don't agree.

@enjoy-binbin
Copy link
Contributor Author

ok, the CI report a rehashing leak in discardTempDb.
because initTempDb does not init the rehashing list, after we swap it, the old rehashing is leaking. There seems to be a lot of hidden code in this piece of code.

Not sure if i should continue

@oranagra
Copy link
Member

i think you should continue.
ideally we would be able to use memset / memcpy, or struct copy. instead of initializing and copying each field separately.
but if that causes complications, i think we should keep handling all fields, just for completeness (and reduce the chance of surprises in the future)

@oranagra oranagra changed the title Swap everything when swap the dbDict Handle missing fields in dbSwapDatabases and swapMainDbWithTempDb Dec 10, 2023
@oranagra oranagra merged commit 62419c0 into redis:unstable Dec 10, 2023
@enjoy-binbin enjoy-binbin deleted the swap_bucket_count branch December 11, 2023 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants