Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RocksDB bug #24

Open
dajitui opened this issue May 30, 2023 · 7 comments
Open

RocksDB bug #24

dajitui opened this issue May 30, 2023 · 7 comments

Comments

@dajitui
Copy link

dajitui commented May 30, 2023

在高并发下,对RocksDB 处理出现数据不一致问题

    @SneakyThrows
    @Test
    public void test() throws RocksDBException {
        System.out.println(getLastIndex());
        System.out.println(get(getLastIndex()));

        System.out.println("-------begin--------");

        int i = 0;

        while (i < 10) {
            int finalI = i;
            CompletableFuture.runAsync(() -> {
                write(new Cmd("hello", "value"));
                System.out.println(finalI +" "+ getLastIndex());

                deleteOnStartIndex(getLastIndex());

                System.out.println(finalI +" "+ getLastIndex());
            });
            i++;
        }

        Thread.sleep(4000);

        System.out.println("----------end----------");

        System.out.println(getLastIndex());

        System.out.println(get(getLastIndex()));

        Thread.sleep(3000);

    }
@kebukeYi
Copy link

image
在红色框中,很有可能 线程A获得锁执行了一次write()函数,随后释放锁;
然后线程C紧接着获得了锁,也执行了一次write()函数,此时 getLastIndex()==2,然后线程A获得锁执行的 deleteOnStartIndex()函数,是从2开始的,因此会出现1位置的日志没有被删除;

@dajitui
Copy link
Author

dajitui commented Jun 27, 2023

image 在红色框中,很有可能 线程A获得锁执行了一次write()函数,随后释放锁; 然后线程C紧接着获得了锁,也执行了一次write()函数,此时 getLastIndex()==2,然后线程A获得锁执行的 deleteOnStartIndex()函数,是从2开始的,因此会出现1位置的日志没有被删除;

getLastIndex跟写操作没有同步

@kebukeYi
Copy link

是没有同步;所以,你是想怎么改???

@dajitui
Copy link
Author

dajitui commented Jun 27, 2023

是没有同步;所以,你是想怎么改???

这个问题简单,可以百度一下或者问下chaigpt

@kebukeYi
Copy link

image
怎么感觉你在自问自答啊?
你明知道那样操作 会出现问题,还把问题抛出来,是想起到一个错误示范作用吗?

@dajitui
Copy link
Author

dajitui commented Jun 27, 2023

我来给你普及一下,github 的issue 是为了开发者提出问题、缺陷。并不是我给了一个错误的示范,而是框架就不严谨,就是java并发没有做好。
我开着三轮车,不说三轮车不行,说开的人有问题,哈哈

@kebukeYi
Copy link

那我就不懂了;那你既然说 解决方法简单,那你大致说一下你的解决思路?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants