|
| 1 | +/* |
| 2 | + * Copyright (c) 2022, SensorsData and/or its affiliates. All rights reserved. |
| 3 | + * SENSORSDATA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
| 4 | + */ |
| 5 | + |
| 6 | +package org.apache.hadoop.hdfs.qjournal.protocolPB; |
| 7 | + |
| 8 | +import java.io.Closeable; |
| 9 | +import java.io.IOException; |
| 10 | +import java.net.InetSocketAddress; |
| 11 | +import java.net.URL; |
| 12 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocol; |
| 13 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetEditLogManifestResponseProto; |
| 14 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetJournalStateResponseProto; |
| 15 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.GetJournaledEditsResponseProto; |
| 16 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.NewEpochResponseProto; |
| 17 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.PrepareRecoveryResponseProto; |
| 18 | +import org.apache.hadoop.hdfs.qjournal.protocol.QJournalProtocolProtos.SegmentStateProto; |
| 19 | +import org.apache.hadoop.hdfs.qjournal.protocol.RequestInfo; |
| 20 | +import org.apache.hadoop.hdfs.server.common.StorageInfo; |
| 21 | +import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; |
| 22 | + |
| 23 | +/** |
| 24 | + * The client is a mock implementation that pretends to access the JournalNode but doesn't perform |
| 25 | + * any actual operations. It provides an interface for blacklisting JournalNode nodes. |
| 26 | + */ |
| 27 | +public class QJournalProtocolFakeTranslatorPB implements QJournalProtocol, Closeable { |
| 28 | + |
| 29 | + private final InetSocketAddress addr; |
| 30 | + |
| 31 | + public QJournalProtocolFakeTranslatorPB(InetSocketAddress addr) { |
| 32 | + this.addr = addr; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void close() throws IOException { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public boolean isFormatted(String journalId, String nameServiceId) throws IOException { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public GetJournalStateResponseProto getJournalState(String journalId, String nameServiceId) |
| 47 | + throws IOException { |
| 48 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void format(String journalId, String nameServiceId, NamespaceInfo nsInfo, boolean force) |
| 53 | + throws IOException { |
| 54 | + throw new IOException("The journalnode " + addr + " is black node, the format operation does " |
| 55 | + + "not support blacklisting"); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public NewEpochResponseProto newEpoch(String journalId, String nameServiceId, |
| 60 | + NamespaceInfo nsInfo, long epoch) throws IOException { |
| 61 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void journal(RequestInfo reqInfo, long segmentTxId, long firstTxnId, int numTxns, |
| 66 | + byte[] records) throws IOException { |
| 67 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public void heartbeat(RequestInfo reqInfo) throws IOException { |
| 72 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public void startLogSegment(RequestInfo reqInfo, long txid, int layoutVersion) |
| 77 | + throws IOException { |
| 78 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 79 | + } |
| 80 | + |
| 81 | + @Override |
| 82 | + public void finalizeLogSegment(RequestInfo reqInfo, long startTxId, long endTxId) |
| 83 | + throws IOException { |
| 84 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 85 | + } |
| 86 | + |
| 87 | + @Override |
| 88 | + public void purgeLogsOlderThan(RequestInfo requestInfo, long minTxIdToKeep) throws IOException { |
| 89 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public GetEditLogManifestResponseProto getEditLogManifest(String jid, String nameServiceId, |
| 94 | + long sinceTxId, boolean inProgressOk) throws IOException { |
| 95 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public GetJournaledEditsResponseProto getJournaledEdits(String jid, String nameServiceId, |
| 100 | + long sinceTxId, int maxTxns) throws IOException { |
| 101 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 102 | + } |
| 103 | + |
| 104 | + @Override |
| 105 | + public PrepareRecoveryResponseProto prepareRecovery(RequestInfo reqInfo, long segmentTxId) |
| 106 | + throws IOException { |
| 107 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public void acceptRecovery(RequestInfo reqInfo, SegmentStateProto stateToAccept, URL fromUrl) |
| 112 | + throws IOException { |
| 113 | + throw new IOException("The journalnode " + addr + " is black node, skip this node."); |
| 114 | + } |
| 115 | + |
| 116 | + @Override |
| 117 | + public void doPreUpgrade(String journalId) throws IOException { |
| 118 | + throw new IOException("The journalnode " + addr + " is black node, the doPreUpgrade operation " |
| 119 | + + "does not support blacklisting"); |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void doUpgrade(String journalId, StorageInfo sInfo) throws IOException { |
| 124 | + throw new IOException("The journalnode " + addr + " is black node, the doUpgrade operation does" |
| 125 | + + " not support blacklisting"); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public void doFinalize(String journalId, String nameServiceid) throws IOException { |
| 130 | + throw new IOException("The journalnode " + addr + " is black node, the doFinalize operation " |
| 131 | + + "does not support blacklisting"); |
| 132 | + } |
| 133 | + |
| 134 | + @Override |
| 135 | + public Boolean canRollBack(String journalId, String nameServiceid, StorageInfo storage, |
| 136 | + StorageInfo prevStorage, int targetLayoutVersion) throws IOException { |
| 137 | + throw new IOException("The journalnode " + addr + " is black node, the canRollBack operation " |
| 138 | + + "does not support blacklisting"); |
| 139 | + } |
| 140 | + |
| 141 | + @Override |
| 142 | + public void doRollback(String journalId, String nameServiceid) throws IOException { |
| 143 | + throw new IOException("The journalnode " + addr + " is black node, the doRollback operation " |
| 144 | + + "does not support blacklisting"); |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + public void discardSegments(String journalId, String nameServiceId, long startTxId) |
| 149 | + throws IOException { |
| 150 | + throw new IOException("The journalnode " + addr + " is black node, the discardSegments " |
| 151 | + + "operation does not support blacklisting"); |
| 152 | + } |
| 153 | + |
| 154 | + @Override |
| 155 | + public Long getJournalCTime(String journalId, String nameServiceId) throws IOException { |
| 156 | + throw new IOException("The journalnode " + addr + " is black node, the getJournalCTime " |
| 157 | + + "operation does not support blacklisting"); |
| 158 | + } |
| 159 | +} |
0 commit comments