2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.persisted;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.io.ByteStreams;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import java.io.DataInput;
16 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
19 import org.opendaylight.controller.cluster.datastore.utils.ImmutableUnsignedLongSet;
20 import org.opendaylight.controller.cluster.raft.persisted.LegacySerializable;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Payload persisted when a local history is instructed some transaction identifiers, i.e. the frontend has used them
26 * for other purposes. It contains a {@link LocalHistoryIdentifier} and a list of transaction identifiers within that
29 public sealed class SkipTransactionsPayload extends AbstractIdentifiablePayload<LocalHistoryIdentifier> {
30 private static final class Magnesium extends SkipTransactionsPayload implements LegacySerializable {
32 private static final long serialVersionUID = 1L;
34 Magnesium(final LocalHistoryIdentifier historyId, final byte[] serialized,
35 final ImmutableUnsignedLongSet transactionIds) {
36 super(historyId, serialized, transactionIds);
40 @Deprecated(since = "7.0.0", forRemoval = true)
41 private static final class Proxy extends AbstractProxy<LocalHistoryIdentifier> {
43 private static final long serialVersionUID = 1L;
45 private ImmutableUnsignedLongSet transactionIds;
47 // checkstyle flags the public modifier as redundant which really doesn't make sense since it clearly isn't
48 // redundant. It is explicitly needed for Java serialization to be able to create instances via reflection.
49 @SuppressWarnings("checkstyle:RedundantModifier")
55 protected LocalHistoryIdentifier readIdentifier(final DataInput in) throws IOException {
56 final var id = LocalHistoryIdentifier.readFrom(in);
57 transactionIds = ImmutableUnsignedLongSet.readFrom(in);
62 protected SkipTransactionsPayload createObject(final LocalHistoryIdentifier identifier,
63 final byte[] serialized) {
64 return new Magnesium(identifier, serialized, verifyNotNull(transactionIds));
68 private static final Logger LOG = LoggerFactory.getLogger(SkipTransactionsPayload.class);
70 private static final long serialVersionUID = 1L;
71 private static final int PROXY_SIZE = externalizableProxySize(ST::new);
73 @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Handled via externalizable proxy")
74 private final @NonNull ImmutableUnsignedLongSet transactionIds;
76 SkipTransactionsPayload(final @NonNull LocalHistoryIdentifier historyId,
77 final byte @NonNull [] serialized, final ImmutableUnsignedLongSet transactionIds) {
78 super(historyId, serialized);
79 this.transactionIds = requireNonNull(transactionIds);
82 public static @NonNull SkipTransactionsPayload create(final LocalHistoryIdentifier historyId,
83 final ImmutableUnsignedLongSet transactionIds, final int initialSerializedBufferCapacity) {
84 final var out = ByteStreams.newDataOutput(initialSerializedBufferCapacity);
86 historyId.writeTo(out);
87 transactionIds.writeTo(out);
88 } catch (IOException e) {
89 // This should never happen
90 LOG.error("Failed to serialize {} ids {}", historyId, transactionIds, e);
91 throw new IllegalStateException("Failed to serialize " + historyId + " ids " + transactionIds, e);
94 return new SkipTransactionsPayload(historyId, out.toByteArray(), transactionIds);
97 public @NonNull ImmutableUnsignedLongSet getTransactionIds() {
98 return transactionIds;
102 protected ST externalizableProxy(final byte[] serialized) {
103 return new ST(serialized);
107 protected int externalizableProxySize() {