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

Prevent bookie shutdown due to rest api when bookie prohibits readOnlyMode #3972

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

wenbingshen
Copy link
Member

Motivation

When bookie disabled readOnlyMode, once the user initiates a readOnly conversion through the rest api, the bookie process will be shut down directly.

public void doTransitionToReadOnlyMode() {
       ......
        if (!conf.isReadOnlyModeEnabled()) {
            LOG.warn("ReadOnly mode is not enabled. "
                    + "Can be enabled by configuring "
                    + "'readOnlyModeEnabled=true' in configuration."
                    + " Shutting down bookie");
            shutdownHandler.shutdown(ExitCode.BOOKIE_EXCEPTION);
            return;
        }
       ......
    }

I have the following reasons for this PR:

  1. If the user wants to shut down the bookie, there is no need to operate it through the rest api, and can directly use the shell shutdown script.
  2. The user switches the readOnly state through the rest api, the first purpose is not to shut down the bookie process;
  3. Exposing the bookie shutdown logic through the rest api has certain security risks.

You can copy the following code to org.apache.bookkeeper.server.http.TestHttpService#testBookieReadOnlyState to reproduce the shutdown of bookie:

        // disable readOnly mode
        restartBookies(c -> {
            c.setForceReadOnlyBookie(false);
            c.setReadOnlyModeEnabled(false);
            return c;
        });
        MetadataBookieDriver metadataDriver = BookieResources.createMetadataDriver(
                baseConf, NullStatsLogger.INSTANCE);
        BKHttpServiceProvider bkHttpServiceProvider2 = new BKHttpServiceProvider.Builder()
                .setBookieServer(serverByIndex(numberOfBookies - 1))
                .setServerConfiguration(baseConf)
                .setLedgerManagerFactory(metadataDriver.getLedgerManagerFactory())
                .build();
       HttpEndpointService bookieReadOnlyService2 = bkHttpServiceProvider2
                .provideHttpEndpointService(HttpServer.ApiType.BOOKIE_STATE_READONLY);

        request = new HttpServiceRequest(JsonUtil.toJson(new ReadOnlyState(true)), HttpServer.Method.PUT,  null);
        response = bookieReadOnlyService2.handle(request);
        Awaitility.await().untilAsserted(() -> {
            assertFalse(serverByIndex(numberOfBookies - 1).isBookieRunning()); // here the bookie will be shutdown.
        });

@hangc0276 hangc0276 added this to the 4.17.0 milestone Jun 13, 2023
@eolivelli eolivelli modified the milestones: 4.17.0, 4.18.0 Mar 29, 2024
@wenbingshen wenbingshen merged commit 1d9e35d into apache:master Apr 29, 2024
@wenbingshen wenbingshen deleted the wenbing/checkReadOnlyEnable branch April 29, 2024 03:14
hezhangjian pushed a commit that referenced this pull request May 25, 2024
hezhangjian pushed a commit that referenced this pull request May 26, 2024
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants