Skip to content

Commit

Permalink
Create utility functions for updating state and getting last transact…
Browse files Browse the repository at this point in the history
…ion number
  • Loading branch information
kr565370 committed Apr 25, 2024
1 parent d8c180a commit ad755e1
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2022-2024 Crown Copyright
*
* Licensed 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 sleeper.core.statestore.transactionlog;

import sleeper.core.statestore.StateStoreException;
import sleeper.core.table.TableStatus;

public class TransactionLogSnapshotUtils {
private TransactionLogSnapshotUtils() {
}

public static long updateFilesState(
TableStatus table, StateStorePartitions state, TransactionLogStore store, long lastTransactionNumber) throws StateStoreException {
return updateState(TransactionLogHead.builder().forPartitions()
.lastTransactionNumber(lastTransactionNumber)
.logStore(store)
.sleeperTable(table)
.state(state)
.build());
}

public static long updatePartitionsState(
TableStatus table, StateStoreFiles state, TransactionLogStore store, long lastTransactionNumber) throws StateStoreException {
return updateState(TransactionLogHead.builder().forFiles()
.lastTransactionNumber(lastTransactionNumber)
.logStore(store)
.sleeperTable(table)
.state(state)
.build());
}

private static long updateState(TransactionLogHead<?> head) throws StateStoreException {
head.update();
return head.lastTransactionNumber();
}
}

0 comments on commit ad755e1

Please sign in to comment.