1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hdfs.server.namenode; 19 20 import java.io.IOException; 21 import java.util.Collection; 22 23 import org.apache.hadoop.hdfs.server.common.Storage; 24 import org.apache.hadoop.hdfs.server.common.StorageInfo; 25 import org.apache.hadoop.hdfs.server.protocol.JournalInfo; 26 import org.apache.hadoop.hdfs.server.protocol.NamenodeRegistration; 27 import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo; 28 29 /** 30 * A JournalManager implementation that uses RPCs to log transactions 31 * to a BackupNode. 32 */ 33 class BackupJournalManager implements JournalManager { 34 private final NamenodeRegistration bnReg; 35 private final JournalInfo journalInfo; 36 BackupJournalManager(NamenodeRegistration bnReg, NamenodeRegistration nnReg)37 BackupJournalManager(NamenodeRegistration bnReg, 38 NamenodeRegistration nnReg) { 39 journalInfo = new JournalInfo(nnReg.getLayoutVersion(), 40 nnReg.getClusterID(), nnReg.getNamespaceID()); 41 this.bnReg = bnReg; 42 } 43 44 @Override format(NamespaceInfo nsInfo)45 public void format(NamespaceInfo nsInfo) { 46 // format() should only get called at startup, before any BNs 47 // can register with the NN. 48 throw new UnsupportedOperationException( 49 "BackupNode journal should never get formatted"); 50 } 51 52 @Override hasSomeData()53 public boolean hasSomeData() { 54 throw new UnsupportedOperationException(); 55 } 56 57 58 @Override startLogSegment(long txId, int layoutVersion)59 public EditLogOutputStream startLogSegment(long txId, int layoutVersion) 60 throws IOException { 61 EditLogBackupOutputStream stm = new EditLogBackupOutputStream(bnReg, 62 journalInfo); 63 stm.startLogSegment(txId); 64 return stm; 65 } 66 67 @Override finalizeLogSegment(long firstTxId, long lastTxId)68 public void finalizeLogSegment(long firstTxId, long lastTxId) 69 throws IOException { 70 } 71 72 @Override setOutputBufferCapacity(int size)73 public void setOutputBufferCapacity(int size) { 74 } 75 76 @Override purgeLogsOlderThan(long minTxIdToKeep)77 public void purgeLogsOlderThan(long minTxIdToKeep) 78 throws IOException { 79 } 80 81 @Override selectInputStreams(Collection<EditLogInputStream> streams, long fromTxnId, boolean inProgressOk)82 public void selectInputStreams(Collection<EditLogInputStream> streams, 83 long fromTxnId, boolean inProgressOk) { 84 // This JournalManager is never used for input. Therefore it cannot 85 // return any transactions 86 } 87 88 @Override recoverUnfinalizedSegments()89 public void recoverUnfinalizedSegments() throws IOException { 90 } 91 92 @Override close()93 public void close() throws IOException {} 94 matchesRegistration(NamenodeRegistration bnReg)95 public boolean matchesRegistration(NamenodeRegistration bnReg) { 96 return bnReg.getAddress().equals(this.bnReg.getAddress()); 97 } 98 99 @Override toString()100 public String toString() { 101 return "BackupJournalManager"; 102 } 103 104 @Override discardSegments(long startTxId)105 public void discardSegments(long startTxId) throws IOException { 106 throw new UnsupportedOperationException(); 107 } 108 109 @Override doPreUpgrade()110 public void doPreUpgrade() throws IOException { 111 throw new UnsupportedOperationException(); 112 } 113 114 @Override doUpgrade(Storage storage)115 public void doUpgrade(Storage storage) throws IOException { 116 throw new UnsupportedOperationException(); 117 } 118 119 @Override doFinalize()120 public void doFinalize() throws IOException { 121 throw new UnsupportedOperationException(); 122 } 123 124 @Override canRollBack(StorageInfo storage, StorageInfo prevStorage, int targetLayoutVersion)125 public boolean canRollBack(StorageInfo storage, StorageInfo prevStorage, 126 int targetLayoutVersion) throws IOException { 127 throw new UnsupportedOperationException(); 128 } 129 130 @Override doRollback()131 public void doRollback() throws IOException { 132 throw new UnsupportedOperationException(); 133 } 134 135 @Override getJournalCTime()136 public long getJournalCTime() throws IOException { 137 throw new UnsupportedOperationException(); 138 } 139 } 140