sashapolo commented on code in PR #1626: URL: https://github.com/apache/ignite-3/pull/1626#discussion_r1099735194
########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/CursorPublisher.java: ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.metastorage.impl; + +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.Flow.Subscriber; +import java.util.function.Function; +import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory; +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.lang.IgniteUuidGenerator; + +/** + * Publisher that streams data from a remote Meta Storage cursor. + * + * @see CursorSubscription + */ +class CursorPublisher implements Publisher<Entry> { + private static final IgniteUuidGenerator UUID_GENERATOR = new IgniteUuidGenerator(UUID.randomUUID(), 0); + + private final RaftGroupService raftService; + + private final MetaStorageCommandsFactory commandsFactory; + + private final ExecutorService executorService; + + private final Function<IgniteUuid, WriteCommand> createCursorSupplier; + + /** + * Creates a new publisher instance. + * + * @param raftService Meta Storage Raft service. + * @param commandsFactory Meta Storage commands factory. + * @param executorService Executor that will be used to call the subscriber's methods. + * @param createCursorSupplier Factory that creates a remote Meta Storage cursor (provided with a cursor ID). + */ + CursorPublisher( + RaftGroupService raftService, + MetaStorageCommandsFactory commandsFactory, + ExecutorService executorService, + Function<IgniteUuid, WriteCommand> createCursorSupplier + ) { + this.raftService = raftService; + this.commandsFactory = commandsFactory; + this.executorService = executorService; + this.createCursorSupplier = createCursorSupplier; + } + + @Override + public void subscribe(Subscriber<? super Entry> subscriber) { + IgniteUuid cursorId = UUID_GENERATOR.randomUuid(); + + WriteCommand createCursorCommand = createCursorSupplier.apply(cursorId); + + raftService.run(createCursorCommand) + .whenCompleteAsync((v, e) -> { + if (e == null) { Review Comment: Makes sense, I always forget about this stuff ########## modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/impl/CursorPublisher.java: ########## @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.metastorage.impl; + +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Flow.Publisher; +import java.util.concurrent.Flow.Subscriber; +import java.util.function.Function; +import org.apache.ignite.internal.metastorage.Entry; +import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory; +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.internal.raft.service.RaftGroupService; +import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.lang.IgniteUuidGenerator; + +/** + * Publisher that streams data from a remote Meta Storage cursor. + * + * @see CursorSubscription + */ +class CursorPublisher implements Publisher<Entry> { + private static final IgniteUuidGenerator UUID_GENERATOR = new IgniteUuidGenerator(UUID.randomUUID(), 0); + + private final RaftGroupService raftService; + + private final MetaStorageCommandsFactory commandsFactory; + + private final ExecutorService executorService; + + private final Function<IgniteUuid, WriteCommand> createCursorSupplier; + + /** + * Creates a new publisher instance. + * + * @param raftService Meta Storage Raft service. + * @param commandsFactory Meta Storage commands factory. + * @param executorService Executor that will be used to call the subscriber's methods. + * @param createCursorSupplier Factory that creates a remote Meta Storage cursor (provided with a cursor ID). + */ + CursorPublisher( + RaftGroupService raftService, + MetaStorageCommandsFactory commandsFactory, + ExecutorService executorService, + Function<IgniteUuid, WriteCommand> createCursorSupplier + ) { + this.raftService = raftService; + this.commandsFactory = commandsFactory; + this.executorService = executorService; + this.createCursorSupplier = createCursorSupplier; + } + + @Override + public void subscribe(Subscriber<? super Entry> subscriber) { + IgniteUuid cursorId = UUID_GENERATOR.randomUuid(); Review Comment: I don't see any technical problems with that (we will simply create multiple cursors, one per subscription). Though I don't think it's useful in any way -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
