apache / distributedlog

Apache DistributedLog
Apache License 2.0
185 stars 74 forks source link

DistributedLogManager's getLastDLSN runs long time, especially after reOpen log stream #202

Closed ArvinDevel closed 7 years ago

ArvinDevel commented 7 years ago

BUG REPORT

  1. Please describe the issue you observed:
ArvinDevel commented 7 years ago

Below is my unit test case, which often fail. `package org.apache.distributedlog;

import static org.junit.Assert.assertEquals;

import java.net.URI; import java.util.Optional; import java.util.concurrent.CountDownLatch; import org.apache.distributedlog.api.AsyncLogWriter; import org.apache.distributedlog.api.DistributedLogManager; import org.apache.distributedlog.api.namespace.Namespace; import org.apache.distributedlog.api.namespace.NamespaceBuilder; import org.apache.distributedlog.common.concurrent.FutureEventListener; import org.apache.distributedlog.exceptions.LogEmptyException; import org.junit.Test;

/**

} `

ArvinDevel commented 7 years ago

After I moved the getLastDLSN() from the logWriter callback to last, I found this test is passed. It's likely there exists dead lock when executing getLastDLSN() in openWriter callback.

sijie commented 7 years ago

@ArvinDevel

dlm.openAsyncLogWriter().whenComplete(new FutureEventListener<AsyncLogWriter>() {
    @Override
    public void onSuccess(AsyncLogWriter asyncLogWriter) {
        LOG.info("[{}] Created log writer {}", name, asyncLogWriter.toString());
        logWriter = asyncLogWriter;
        try {
            LOG.info("before getLastDLSN");
            last = dlm.getLastDLSN();
            LOG.info("after getLastDLSN");
        } catch (LogEmptyException lee){
            LOG.info("the log stream is empty ");
        } catch (Exception e){
            LOG.error("Faced Exception in getLastDLSN", e);
        }
        LOG.info("getLastDLSN return {}", last);
        openLatch.countDown();
    }

    @Override
    public void onFailure(Throwable throwable) {
        LOG.error("Failed open AsyncLogWriter for {}", name, throwable);
        openLatch.countDown();
    }
});

You can call synchronous function in an asynchronous callback. since the synchronous function is blocking the callback thread. so getLastDLSN will never complete.