Skip to content

Conversation

@Altahrim
Copy link
Collaborator

@Altahrim Altahrim commented Oct 13, 2025

Summary

TODO

Implementation notes

Format

Snowflake IDs use 64 bits. I chose to split them like this:

  • 1 bit : unused, PHP use signed integers
  • 31 bits: Timestamp from 2025-10-01. Allows to store a bit more than 68 years.
  • 10 bits: Milliseconds
  • 9 bits: Server ID
  • 1 bit : CLI or Web (see "Sequence ID" later)
  • 12 bits: Sequence ID

Issues with 32 bits

On 32 bits systems, 64 bits int are stored in float.
The problem is float are losing precision with large numbers like numbers used here so when loading a number, the sequence ID can change.
So, Snowflake IDs are given as string for 64 bits and 32 bits systems.

Server ID

For now, take a hash of hostname. Can be improved with a mapping of server with a server ID.

Sequence ID

PHP-FPM and Apache module share memory and allow the use of apcu_inc to keep sequence ID.
For CLI, fallback to random (shared cache dropped)

Decode tool

occ decode-snowflake 6768789079123765868
+--------------------+-------------------------+
| Snowflake ID       | 6768789079123765868     |
| Seconds            | 1575981518              |
| Milliseconds       | 50                      |
| Created from CLI   | no                      |
| Server ID          | 441                     |
| Sequence ID        | 2668                    |
| Creation timestamp | 3335258318.050          |
| Creation date      | 2075-09-09 12:38:38.050 |
+--------------------+-------------------------+

TODO

  • Add test for 32 bit generation

Checklist

@Altahrim Altahrim added this to the Nextcloud 33 milestone Oct 13, 2025
@Altahrim Altahrim self-assigned this Oct 13, 2025
@Altahrim Altahrim added the 2. developing Work in progress label Oct 13, 2025
@github-project-automation github-project-automation bot moved this to 🏗️ In progress in 📁 Files team Oct 13, 2025
@SystemKeeper
Copy link
Contributor

Is it additional to #55710? 🤔

@Altahrim
Copy link
Collaborator Author

Is it additional to #55710? 🤔

Not really… We discussed it at Contributor Week but I lacked time to finish so I just pushed what I had.
Implementations are a bit different… I added a bit to know if ID was created from CLI because we can't use APCu for it.

@Altahrim Altahrim force-pushed the feat/snowflakeIds branch 22 times, most recently from ff2de9d to c655e83 Compare October 17, 2025 08:18
@Altahrim Altahrim force-pushed the feat/snowflakeIds branch 8 times, most recently from 36b621a to 2b85fe3 Compare October 21, 2025 11:25
@Altahrim

This comment was marked as outdated.

@Altahrim Altahrim force-pushed the feat/snowflakeIds branch 3 times, most recently from d187a2e to a62c8b2 Compare October 23, 2025 08:33
@CarlSchwan

This comment was marked as resolved.

@Altahrim Altahrim removed the pending documentation This pull request needs an associated documentation update label Oct 23, 2025
@Altahrim
Copy link
Collaborator Author

Unrelated red CI, documentation added in nextcloud/documentation#13811

@artonge artonge mentioned this pull request Oct 28, 2025
11 tasks
Altahrim and others added 2 commits October 28, 2025 17:50
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
Allow to get an id for the storing the preview on disk before inserting
the preview on the DB.

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
@Altahrim Altahrim enabled auto-merge October 29, 2025 07:59
@skjnldsv skjnldsv disabled auto-merge October 29, 2025 08:11
@skjnldsv skjnldsv merged commit 52a9940 into master Oct 29, 2025
222 of 239 checks passed
@skjnldsv skjnldsv deleted the feat/snowflakeIds branch October 29, 2025 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

Status: 🏗️ In progress

Development

Successfully merging this pull request may close these issues.

5 participants