Git Product home page Git Product logo

fauxflake's Issues

docker container causes same id to be generated every time

For some reason whenever I run an application using fauxflake inside a docker,
it always generates the same id (this is a single long running instance of a linux container),
even if the container stays up and has net=host set.

private static IdGenerator snowflake = IdGenerators.newSnowflakeIdGenerator();
snowflake.generateId(1000).asString();

always yields ffffffffffc01000

works perfectly outside the container though.

EncodingProviders must use abs(machine id)

Negative machine IDs are possible, and SnowflakeEncodingProvider left-shifts these without checking, resulting in a small negative number that is OR'ed with the timestamp, erasing the timestamp. Example:

    static class FixedIdProvider implements MachineIdProvider {
        final long id;
        FixedIdProvider(long id) {
            this.id = id;
        }
        public long getMachineId() {
            return id;
        }
    }

    public static void main(String[] args) throws Exception
    {
        IdGenerator g1 = newSnowflakeIdGenerator(new FixedIdProvider(1));
        System.out.println(g1.generateId(0).asString());
        IdGenerator g2 = newSnowflakeIdGenerator(new FixedIdProvider(-1));
        System.out.println(g2.generateId(0).asString());
    }

Output:

080f6b18b1001000
fffffffffffff000

Creating a wrapper on e.g. MacPidMachineIdProvider is an easy temporary workaround.

duplicate ids being generated

I was a bit surprised to see that this code in a unit test produces two duplicates:

        IdGenerator snowflake = IdGenerators.newSnowflakeIdGenerator();
        for (int i = 0; i < 10; i++) {
            String id = snowflake.generateId(1000).asString();
            System.out.println(id);
        }

output:

ffffffffffed8000
ffffffffffed8000
ffffffffffed8001
ffffffffffed8002
ffffffffffed8003
ffffffffffed8004
ffffffffffed8005
ffffffffffed8006
ffffffffffed8000
ffffffffffed8001

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.