2 分布式算法

2021-06-26  本文已影响0人  格林哈

1 分布式事务算法

2 cap

3 Base 理论

3.1 三要素讲解

2 CRDT

2.1 符合CRDT的条件

2.2 概念和名词

2.3 类型

2.4 常见数据类型

时间 客户端A 客户端B
初始时刻 arryA[A,B]={0,0} arryB[A,B]={0,0}
t时刻 update arryA[A+1,B]={1,0} arryB[A,B+2]={0,2}
t2时刻 merge max(arryA,arryB) arryA[A,B]={1,2} arryB[A,B]={1,2}
t3时刻 query sum(arry) 3 3
        <!--wurmloch-crdt的实现-->
        <dependency>
            <groupId>com.netopyr.wurmloch</groupId>
            <artifactId>wurmloch-crdt</artifactId>
            <version>0.1.0</version>
        </dependency>

  @Test
    public void testPNCount() {
        LocalCrdtStore crdtStore1 = new LocalCrdtStore();
        LocalCrdtStore crdtStore2 = new LocalCrdtStore();
        crdtStore1.connect(crdtStore2);

        PNCounter replica1 = crdtStore1.createPNCounter("ID_1");
        PNCounter replica2 = crdtStore2.findPNCounter("ID_1").get();

        replica1.increment();
        replica2.decrement(2L);

        System.out.println(replica1.get() == -1L);
        System.out.println(replica2.get() == -1L);


        crdtStore1.disconnect(crdtStore2);

        replica1.decrement(3L);
        replica2.increment(5L);

        System.out.println(replica1.get() == -4L);
        System.out.println(replica2.get() == 4L);


        crdtStore1.connect(crdtStore2);

        System.out.println(replica1.get() == 1L);
        System.out.println(replica2.get() == 1L);

    }
上一篇 下一篇

猜你喜欢

热点阅读