Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
それが twitter スノーフレークのコアであるコードを説明できる人。
long nextId = ((timestamp - twepoch) << this.timestampLeftShift) | (this.workerId << this.workerIdShift) | (this.sequence);
アルゴリズムの考え方を知りたいのですが、なぜ実装するのですか?
Twitterのスノーフレークサービスは、分散環境で一意のIDを作成します。多数のワーカープロセスがそれぞれ一意のIDを割り当てることができます。IDは、時間、ワーカーID、シーケンス番号の3つのコンポーネントで構成されます。単純なコード行は、これら3つのコンポーネントをシフトして、64ビットの結果でオーバーラップしないようにするか、またはそれらを組み合わせて単一の64ビットの結果を作成します。