org.apache.bookkeeper.net.BookieSocketAddress Java Examples
The following examples show how to use
org.apache.bookkeeper.net.BookieSocketAddress.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 6 votes |
private int bkRecovery(final LinkedBlockingQueue<Long> ledgers, final Set<BookieSocketAddress> bookieAddrs, final boolean dryrun, final boolean skipOpenLedgers) throws Exception { return runBKCommand(new BKCommandRunner() { @Override public int run(ZooKeeperClient zkc, BookKeeperClient bkc) throws Exception { BookKeeperAdmin bkAdmin = new BookKeeperAdmin(bkc.get()); try { bkRecovery(bkAdmin, ledgers, bookieAddrs, dryrun, skipOpenLedgers); return 0; } finally { bkAdmin.close(); } } }); }
Example #2
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 6 votes |
private Map<Long, Integer> inspectLedger(LedgerMetadata metadata, Set<BookieSocketAddress> bookiesToInspect) { Map<Long, Integer> numBookiesToReplacePerEnsemble = new TreeMap<Long, Integer>(); for (Map.Entry<Long, ArrayList<BookieSocketAddress>> ensemble : metadata.getEnsembles().entrySet()) { ArrayList<BookieSocketAddress> bookieList = ensemble.getValue(); System.out.print(ensemble.getKey() + ":\t"); int numBookiesToReplace = 0; for (BookieSocketAddress bookie: bookieList) { System.out.print(bookie.toString()); if (bookiesToInspect.contains(bookie)) { System.out.print("*"); ++numBookiesToReplace; } else { System.out.print(" "); } System.out.print(" "); } System.out.println(); numBookiesToReplacePerEnsemble.put(ensemble.getKey(), numBookiesToReplace); } return numBookiesToReplacePerEnsemble; }
Example #3
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 6 votes |
private int bkQuery(BookKeeperAdmin bkAdmin, Set<BookieSocketAddress> bookieAddrs) throws InterruptedException, BKException { SortedMap<Long, LedgerMetadata> ledgersContainBookies = bkAdmin.getLedgersContainBookies(bookieAddrs); System.err.println("NOTE: Bookies in inspection list are marked with '*'."); for (Map.Entry<Long, LedgerMetadata> ledger : ledgersContainBookies.entrySet()) { System.out.println("ledger " + ledger.getKey() + " : " + ledger.getValue().getState()); Map<Long, Integer> numBookiesToReplacePerEnsemble = inspectLedger(ledger.getValue(), bookieAddrs); System.out.print("summary: ["); for (Map.Entry<Long, Integer> entry : numBookiesToReplacePerEnsemble.entrySet()) { System.out.print(entry.getKey() + "=" + entry.getValue() + ", "); } System.out.println("]"); System.out.println(); } System.out.println("Done"); return 0; }
Example #4
Source File: OffloadIndexTest.java From pulsar with Apache License 2.0 | 6 votes |
private LedgerMetadata createLedgerMetadata() throws Exception { Map<String, byte[]> metadataCustom = Maps.newHashMap(); metadataCustom.put("key1", "value1".getBytes(UTF_8)); metadataCustom.put("key7", "value7".getBytes(UTF_8)); ArrayList<BookieSocketAddress> bookies = Lists.newArrayList(); BookieSocketAddress BOOKIE1 = new BookieSocketAddress("127.0.0.1:3181"); BookieSocketAddress BOOKIE2 = new BookieSocketAddress("127.0.0.2:3181"); BookieSocketAddress BOOKIE3 = new BookieSocketAddress("127.0.0.3:3181"); bookies.add(0, BOOKIE1); bookies.add(1, BOOKIE2); bookies.add(2, BOOKIE3); return LedgerMetadataBuilder.create().withEnsembleSize(3).withWriteQuorumSize(3).withAckQuorumSize(2) .withDigestType(DigestType.CRC32C).withPassword("password".getBytes(UTF_8)) .withCustomMetadata(metadataCustom).withClosedState().withLastEntryId(5000).withLength(100) .newEnsembleEntry(0L, bookies).build(); }
Example #5
Source File: ZkBookieRackAffinityMapping.java From pulsar with Apache License 2.0 | 6 votes |
@Override public void onUpdate(String path, BookiesRackConfiguration data, Stat stat) { if (rackawarePolicy != null) { LOG.info("Bookie rack info updated to {}. Notifying rackaware policy.", data.toString()); List<BookieSocketAddress> bookieAddressList = new ArrayList<>(); for (Map<String, BookieInfo> bookieMapping : data.values()) { for (String addr : bookieMapping.keySet()) { try { bookieAddressList.add(new BookieSocketAddress(addr)); } catch (UnknownHostException e) { throw new RuntimeException(e); } } } rackawarePolicy.onBookieRackChange(bookieAddressList); } }
Example #6
Source File: BrokerBookieIsolationTest.java From pulsar with Apache License 2.0 | 6 votes |
private void setDefaultIsolationGroup(String brokerBookkeeperClientIsolationGroups, ZooKeeper zkClient, Set<BookieSocketAddress> bookieAddresses) throws Exception { BookiesRackConfiguration bookies = null; try { byte[] data = zkClient.getData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, false, null); System.out.println(new String(data)); bookies = jsonMapper.readValue(data, BookiesRackConfiguration.class); } catch (KeeperException.NoNodeException e) { // Ok.. create new bookie znode zkClient.create(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, "".getBytes(), Acl, CreateMode.PERSISTENT); } if (bookies == null) { bookies = new BookiesRackConfiguration(); } Map<String, BookieInfo> bookieInfoMap = Maps.newHashMap(); for (BookieSocketAddress bkSocket : bookieAddresses) { BookieInfo info = new BookieInfo("use", bkSocket.getHostName() + ":" + bkSocket.getPort()); bookieInfoMap.put(bkSocket.toString(), info); } bookies.put(brokerBookkeeperClientIsolationGroups, bookieInfoMap); zkClient.setData(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookies), -1); }
Example #7
Source File: ZkBookieRackAffinityMapping.java From pulsar with Apache License 2.0 | 5 votes |
private void updateRacksWithHost(BookiesRackConfiguration racks) { // In config z-node, the bookies are added in the `ip:port` notation, while BK will ask // for just the IP/hostname when trying to get the rack for a bookie. // To work around this issue, we insert in the map the bookie ip/hostname with same rack-info BookiesRackConfiguration newRacksWithHost = new BookiesRackConfiguration(); Map<String, BookieInfo> newBookieInfoMap = new HashMap<>(); racks.forEach((group, bookies) -> bookies.forEach((addr, bi) -> { try { BookieSocketAddress bsa = new BookieSocketAddress(addr); newRacksWithHost.updateBookie(group, bsa.toString(), bi); String hostname = bsa.getSocketAddress().getHostName(); newBookieInfoMap.put(hostname, bi); InetAddress address = bsa.getSocketAddress().getAddress(); if (null != address) { String hostIp = address.getHostAddress(); if (null != hostIp) { newBookieInfoMap.put(hostIp, bi); } } else { LOG.info("Network address for {} is unresolvable yet.", addr); } } catch (UnknownHostException e) { throw new RuntimeException(e); } }) ); racksWithHost = newRacksWithHost; bookieInfoMap = newBookieInfoMap; }
Example #8
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 5 votes |
private int bkRecovery(final BookKeeperAdmin bkAdmin, final LinkedBlockingQueue<Long> ledgers, final Set<BookieSocketAddress> bookieAddrs, final boolean dryrun, final boolean skipOpenLedgers) throws InterruptedException, BKException { final AtomicInteger numPendings = new AtomicInteger(ledgers.size()); final ExecutorService executorService = Executors.newCachedThreadPool(); final CountDownLatch doneLatch = new CountDownLatch(concurrency); Runnable r = new Runnable() { @Override public void run() { while (!ledgers.isEmpty()) { long lid = -1L; try { lid = ledgers.take(); System.out.println("Recovering ledger " + lid); bkAdmin.recoverBookieData(lid, bookieAddrs, dryrun, skipOpenLedgers); System.out.println("Recovered ledger completed : " + lid + ", " + numPendings.decrementAndGet() + " left"); } catch (InterruptedException e) { Thread.currentThread().interrupt(); doneLatch.countDown(); break; } catch (BKException ke) { System.out.println("Recovered ledger failed : " + lid + ", rc = " + BKException.getMessage(ke.getCode())); } } doneLatch.countDown(); } }; for (int i = 0; i < concurrency; i++) { executorService.submit(r); } doneLatch.await(); SchedulerUtils.shutdownScheduler(executorService, 2, TimeUnit.MINUTES); return 0; }
Example #9
Source File: LogSegmentSplit.java From distributedlog with Apache License 2.0 | 5 votes |
@Override public String[] getLocations() throws IOException, InterruptedException { Set<String> locations = Sets.newHashSet(); for (ArrayList<BookieSocketAddress> ensemble : ledgerMetadata.getEnsembles().values()) { for (BookieSocketAddress host : ensemble) { locations.add(host.getHostName()); } } return locations.toArray(new String[locations.size()]); }
Example #10
Source File: RackAwareTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testPlacement() throws Exception { for (int i = 0; i < NUM_BOOKIES; i++) { String bookie = bookies.get(i).getLocalAddress().toString(); // Place bookie-1 in "rack-1" and the rest in "rack-2" int rackId = i == 0 ? 1 : 2; BookieInfo bi = new BookieInfo("rack-" + rackId, "bookie-" + (i + 1)); log.info("setting rack for bookie at {} -- {}", bookie, bi); admin.bookies().updateBookieRackInfo(bookie, "default", bi); } // Make sure the racks cache gets updated through the ZK watch Thread.sleep(1000); BookKeeper bkc = this.pulsar.getBookKeeperClient(); // Create few ledgers and verify all of them should have a copy in the first bookie BookieSocketAddress fistBookie = bookies.get(0).getLocalAddress(); for (int i = 0; i < 100; i++) { LedgerHandle lh = bkc.createLedger(2, 2, DigestType.DUMMY, new byte[0]); log.info("Ledger: {} -- Ensemble: {}", i, lh.getLedgerMetadata().getEnsembleAt(0)); assertTrue(lh.getLedgerMetadata().getEnsembleAt(0).contains(fistBookie), "first bookie in rack 0 not included in ensemble"); lh.close(); } }
Example #11
Source File: BrokerBookieIsolationTest.java From pulsar with Apache License 2.0 | 5 votes |
private void assertAffinityBookies(LedgerManager ledgerManager, List<LedgerInfo> ledgers1, Set<BookieSocketAddress> defaultBookies) throws Exception { for (LedgerInfo lInfo : ledgers1) { long ledgerId = lInfo.getLedgerId(); CompletableFuture<Versioned<LedgerMetadata>> ledgerMetaFuture = ledgerManager.readLedgerMetadata(ledgerId); LedgerMetadata ledgerMetadata = ledgerMetaFuture.get().getValue(); Set<BookieSocketAddress> ledgerBookies = Sets.newHashSet(); ledgerBookies.addAll(ledgerMetadata.getAllEnsembles().values().iterator().next()); assertEquals(ledgerBookies.size(), defaultBookies.size()); ledgerBookies.removeAll(defaultBookies); assertEquals(ledgerBookies.size(), 0); } }
Example #12
Source File: BookKeeperClusterTestCase.java From pulsar with Apache License 2.0 | 5 votes |
/** * Get bookie address for bookie at index */ public BookieSocketAddress getBookie(int index) throws Exception { if (bs.size() <= index || index < 0) { throw new IllegalArgumentException( "Invalid index, there are only " + bs.size() + " bookies. Asked for " + index); } return bs.get(index).getLocalAddress(); }
Example #13
Source File: ZkIsolatedBookieEnsemblePlacementPolicy.java From pulsar with Apache License 2.0 | 5 votes |
@Override public PlacementResult<List<BookieSocketAddress>> newEnsemble(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, Set<BookieSocketAddress> excludeBookies) throws BKNotEnoughBookiesException { Set<BookieSocketAddress> blacklistedBookies = getBlacklistedBookies(ensembleSize); if (excludeBookies == null) { excludeBookies = new HashSet<BookieSocketAddress>(); } excludeBookies.addAll(blacklistedBookies); return super.newEnsemble(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, excludeBookies); }
Example #14
Source File: ZkIsolatedBookieEnsemblePlacementPolicy.java From pulsar with Apache License 2.0 | 5 votes |
@Override public PlacementResult<BookieSocketAddress> replaceBookie(int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, List<BookieSocketAddress> currentEnsemble, BookieSocketAddress bookieToReplace, Set<BookieSocketAddress> excludeBookies) throws BKNotEnoughBookiesException { Set<BookieSocketAddress> blacklistedBookies = getBlacklistedBookies(ensembleSize); if (excludeBookies == null) { excludeBookies = new HashSet<BookieSocketAddress>(); } excludeBookies.addAll(blacklistedBookies); return super.replaceBookie(ensembleSize, writeQuorumSize, ackQuorumSize, customMetadata, currentEnsemble, bookieToReplace, excludeBookies); }
Example #15
Source File: ZkBookieRackAffinityMappingTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod public void setUp() throws Exception { localZkS = new ZookeeperServerTest(0); localZkS.start(); localZkc = ZooKeeperClient.newBuilder().connectString("127.0.0.1:" + localZkS.getZookeeperPort()).build(); BOOKIE1 = new BookieSocketAddress("127.0.0.1:3181"); BOOKIE2 = new BookieSocketAddress("127.0.0.2:3181"); BOOKIE3 = new BookieSocketAddress("127.0.0.3:3181"); }
Example #16
Source File: ZkBookieRackAffinityMappingTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testNoBookieInfo() throws Exception { ZkBookieRackAffinityMapping mapping = new ZkBookieRackAffinityMapping(); ClientConfiguration bkClientConf = new ClientConfiguration(); bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache("test", localZkc, 30) { }); mapping.setConf(bkClientConf); List<String> racks = mapping.resolve(Lists.newArrayList("127.0.0.1", "127.0.0.2", "127.0.0.3")); assertEquals(racks.get(0), null); assertEquals(racks.get(1), null); assertEquals(racks.get(2), null); Map<String, Map<BookieSocketAddress, BookieInfo>> bookieMapping = new HashMap<>(); Map<BookieSocketAddress, BookieInfo> mainBookieGroup = new HashMap<>(); mainBookieGroup.put(BOOKIE1, new BookieInfo("/rack0", null)); mainBookieGroup.put(BOOKIE2, new BookieInfo("/rack1", null)); bookieMapping.put("group1", mainBookieGroup); ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, jsonMapper.writeValueAsBytes(bookieMapping), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Thread.sleep(100); racks = mapping.resolve(Lists.newArrayList("127.0.0.1", "127.0.0.2", "127.0.0.3")); assertEquals(racks.get(0), "/rack0"); assertEquals(racks.get(1), "/rack1"); assertEquals(racks.get(2), null); localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1); }
Example #17
Source File: ZkIsolatedBookieEnsemblePlacementPolicyTest.java From pulsar with Apache License 2.0 | 5 votes |
@BeforeMethod public void setUp() throws Exception { timer = new HashedWheelTimer(); localZkS = new ZookeeperServerTest(0); localZkS.start(); localZkc = ZooKeeperClient.newBuilder().connectString("127.0.0.1" + ":" + localZkS.getZookeeperPort()).build(); writableBookies.add(new BookieSocketAddress(BOOKIE1)); writableBookies.add(new BookieSocketAddress(BOOKIE2)); writableBookies.add(new BookieSocketAddress(BOOKIE3)); writableBookies.add(new BookieSocketAddress(BOOKIE4)); isolationGroups.add("group1"); }
Example #18
Source File: ZkIsolatedBookieEnsemblePlacementPolicyTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testNoBookieInfo() throws Exception { ZkIsolatedBookieEnsemblePlacementPolicy isolationPolicy = new ZkIsolatedBookieEnsemblePlacementPolicy(); ClientConfiguration bkClientConf = new ClientConfiguration(); bkClientConf.setProperty(ZooKeeperCache.ZK_CACHE_INSTANCE, new ZooKeeperCache("test", localZkc, 30) { }); bkClientConf.setProperty(ZkIsolatedBookieEnsemblePlacementPolicy.ISOLATION_BOOKIE_GROUPS, isolationGroups); isolationPolicy.initialize(bkClientConf, Optional.empty(), timer, SettableFeatureProvider.DISABLE_ALL, NullStatsLogger.INSTANCE); isolationPolicy.onClusterChanged(writableBookies, readOnlyBookies); isolationPolicy.newEnsemble(4, 4, 4, Collections.emptyMap(), new HashSet<>()); String data = "{\"group1\": {\"" + BOOKIE1 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie1.example.com\"}, \"" + BOOKIE2 + "\": {\"rack\": \"rack1\", \"hostname\": \"bookie2.example.com\"}}, \"group2\": {\"" + BOOKIE3 + "\": {\"rack\": \"rack0\", \"hostname\": \"bookie3.example.com\"}, \"" + BOOKIE4 + "\": {\"rack\": \"rack2\", \"hostname\": \"bookie4.example.com\"}}}"; ZkUtils.createFullPathOptimistic(localZkc, ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, data.getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Thread.sleep(100); List<BookieSocketAddress> ensemble = isolationPolicy.newEnsemble(2, 2, 2, Collections.emptyMap(), new HashSet<>()).getResult(); assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE1))); assertTrue(ensemble.contains(new BookieSocketAddress(BOOKIE2))); try { isolationPolicy.newEnsemble(3, 3, 3, Collections.emptyMap(), new HashSet<>()); fail("should not pass"); } catch (BKNotEnoughBookiesException e) { // ok } localZkc.delete(ZkBookieRackAffinityMapping.BOOKIE_INFO_ROOT_PATH, -1); }
Example #19
Source File: PulsarMockLedgerHandle.java From pulsar with Apache License 2.0 | 5 votes |
private static LedgerMetadata createMetadata(DigestType digest, byte[] passwd) { List<BookieSocketAddress> ensemble = Lists.newArrayList( new BookieSocketAddress("192.0.2.1", 1234), new BookieSocketAddress("192.0.2.2", 1234), new BookieSocketAddress("192.0.2.3", 1234)); return LedgerMetadataBuilder.create() .withDigestType(digest.toApiDigestType()) .withPassword(passwd) .newEnsembleEntry(0L, ensemble) .build(); }
Example #20
Source File: PreferLocalBookiePlacementPolicy.java From herddb with Apache License 2.0 | 5 votes |
@Override public synchronized Set<BookieSocketAddress> onClusterChanged( Set<BookieSocketAddress> writableBookies, Set<BookieSocketAddress> readOnlyBookies ) { HashSet<BookieSocketAddress> deadBookies; deadBookies = new HashSet<>(knownBookies); deadBookies.removeAll(writableBookies); // readonly bookies should not be treated as dead bookies deadBookies.removeAll(readOnlyBookies); knownBookies = writableBookies; return deadBookies; }
Example #21
Source File: PreferLocalBookiePlacementPolicy.java From herddb with Apache License 2.0 | 5 votes |
@Override public PlacementResult<BookieSocketAddress> replaceBookie( int ensembleSize, int writeQuorumSize, int ackQuorumSize, Map<String, byte[]> customMetadata, List<BookieSocketAddress> currentEnsemble, BookieSocketAddress bookieToReplace, Set<BookieSocketAddress> excludeBookies ) throws BKNotEnoughBookiesException { excludeBookies.addAll(currentEnsemble); PlacementResult<List<BookieSocketAddress>> list = newEnsemble(1, 1, 1, customMetadata, excludeBookies); return PlacementResult.of(list.getResult().get(0), PlacementPolicyAdherence.MEETS_STRICT); }
Example #22
Source File: PreferLocalBookiePlacementPolicyTest.java From herddb with Apache License 2.0 | 5 votes |
@Test public void testEnsamblePolicySingle() throws Exception { BookieSocketAddress a = new BookieSocketAddress("a.localhost", 3181); Set<BookieSocketAddress> writableBookies = new HashSet<>(); writableBookies.add(a); registerLocalBookieAddress.invoke(null, a); try { Set<BookieSocketAddress> readOnlyBookies = Collections.emptySet(); PreferLocalBookiePlacementPolicy policy = new PreferLocalBookiePlacementPolicy(); Set<BookieSocketAddress> deadBookies = policy.onClusterChanged(writableBookies, readOnlyBookies); assertTrue(deadBookies.isEmpty()); List<BookieSocketAddress> ensemble = policy.newEnsemble(1, 1, 1, Collections.emptyMap(), Collections.emptySet()).getResult(); System.out.println(ensemble); assertEquals(1, ensemble.size()); assertEquals(a, ensemble.get(0)); } finally { unregisterLocalBookieAddress.invoke(null, a); } }
Example #23
Source File: PreferLocalBookiePlacementPolicyTest.java From herddb with Apache License 2.0 | 5 votes |
@Test public void testEnsamblePolicyMultiple() throws Exception { BookieSocketAddress a = new BookieSocketAddress("a.localhost", 3181); BookieSocketAddress b = new BookieSocketAddress("b.localhost", 3181); BookieSocketAddress c = new BookieSocketAddress("c.localhost", 3181); BookieSocketAddress d = new BookieSocketAddress("d.localhost", 3181); BookieSocketAddress e = new BookieSocketAddress("e.localhost", 3181); Set<BookieSocketAddress> writableBookies = new HashSet<>(); writableBookies.add(a); writableBookies.add(b); writableBookies.add(c); writableBookies.add(d); writableBookies.add(e); registerLocalBookieAddress.invoke(null, c); try { Set<BookieSocketAddress> readOnlyBookies = Collections.emptySet(); PreferLocalBookiePlacementPolicy policy = new PreferLocalBookiePlacementPolicy(); Set<BookieSocketAddress> deadBookies = policy.onClusterChanged(writableBookies, readOnlyBookies); assertTrue(deadBookies.isEmpty()); List<BookieSocketAddress> ensemble = policy.newEnsemble(3, 2, 2, Collections.emptyMap(), Collections.emptySet()).getResult(); System.out.println(ensemble); assertEquals(3, ensemble.size()); assertEquals(c, ensemble.get(0)); } finally { unregisterLocalBookieAddress.invoke(null, c); } }
Example #24
Source File: LedgerReader.java From distributedlog with Apache License 2.0 | 5 votes |
public void readLacs(final LedgerHandle lh, long eid, final GenericCallback<Set<ReadResult<Long>>> callback) { WriteSet writeSet = lh.distributionSchedule.getWriteSet(eid); final AtomicInteger numBookies = new AtomicInteger(writeSet.size()); final Set<ReadResult<Long>> readResults = new HashSet<ReadResult<Long>>(); ReadEntryCallback readEntryCallback = (rc, lid, eid1, buffer, ctx) -> { InetSocketAddress bookieAddress = (InetSocketAddress) ctx; ReadResult<Long> rr; if (BKException.Code.OK != rc) { rr = new ReadResult<Long>(eid1, rc, null, bookieAddress); } else { try { DigestManager.RecoveryData data = lh.macManager.verifyDigestAndReturnLastConfirmed(buffer); rr = new ReadResult<Long>(eid1, BKException.Code.OK, data.lastAddConfirmed, bookieAddress); } catch (BKException.BKDigestMatchException e) { rr = new ReadResult<Long>(eid1, BKException.Code.DigestMatchException, null, bookieAddress); } } readResults.add(rr); if (numBookies.decrementAndGet() == 0) { callback.operationComplete(BKException.Code.OK, readResults); } }; ArrayList<BookieSocketAddress> ensemble = lh.getLedgerMetadata().getEnsemble(eid); for (int i = 0; i < writeSet.size(); i++) { int idx = writeSet.get(i); bookieClient.readEntry(ensemble.get(idx), lh.getId(), eid, readEntryCallback, ensemble.get(idx)); } }
Example #25
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 5 votes |
private Map<BookieSocketAddress, Integer> getBookieStats(LogSegmentMetadata segment) throws Exception { Map<BookieSocketAddress, Integer> stats = new HashMap<BookieSocketAddress, Integer>(); LedgerHandle lh = bkc.client().get().openLedgerNoRecovery(segment.getLogSegmentId(), BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); long eidFirst = 0; for (SortedMap.Entry<Long, ArrayList<BookieSocketAddress>> entry : LedgerReader.bookiesForLedger(lh).entrySet()) { long eidLast = entry.getKey().longValue(); long count = eidLast - eidFirst + 1; for (BookieSocketAddress bookie : entry.getValue()) { merge(stats, bookie, (int) count); } eidFirst = eidLast; } return stats; }
Example #26
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 5 votes |
void merge(Map<BookieSocketAddress, Integer> m, BookieSocketAddress bookie, Integer count) { if (m.containsKey(bookie)) { m.put(bookie, count + m.get(bookie).intValue()); } else { m.put(bookie, count); } }
Example #27
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 5 votes |
private Map<BookieSocketAddress, Integer> getBookieStats(LogSegmentMetadata segment) throws Exception { Map<BookieSocketAddress, Integer> stats = new HashMap<BookieSocketAddress, Integer>(); LedgerHandle lh = bkc.client().get().openLedgerNoRecovery(segment.getLedgerId(), BookKeeper.DigestType.CRC32, getConf().getBKDigestPW().getBytes(UTF_8)); long eidFirst = 0; for (SortedMap.Entry<Long, ArrayList<BookieSocketAddress>> entry : LedgerReader.bookiesForLedger(lh).entrySet()) { long eidLast = entry.getKey().longValue(); long count = eidLast - eidFirst + 1; for (BookieSocketAddress bookie : entry.getValue()) { merge(stats, bookie, (int) count); } eidFirst = eidLast; } return stats; }
Example #28
Source File: DistributedLogTool.java From distributedlog with Apache License 2.0 | 5 votes |
void merge(Map<BookieSocketAddress, Integer> m, BookieSocketAddress bookie, Integer count) { if (m.containsKey(bookie)) { m.put(bookie, count + m.get(bookie).intValue()); } else { m.put(bookie, count); } }
Example #29
Source File: OffloadUtils.java From pulsar with Apache License 2.0 | 4 votes |
public static LedgerMetadata parseLedgerMetadata(byte[] bytes) throws IOException { DataFormats.LedgerMetadataFormat ledgerMetadataFormat = DataFormats.LedgerMetadataFormat.newBuilder().mergeFrom(bytes).build(); LedgerMetadataBuilder builder = LedgerMetadataBuilder.create() .withLastEntryId(ledgerMetadataFormat.getLastEntryId()) .withPassword(ledgerMetadataFormat.getPassword().toByteArray()) .withClosedState() .withMetadataFormatVersion(2) .withLength(ledgerMetadataFormat.getLength()) .withAckQuorumSize(ledgerMetadataFormat.getAckQuorumSize()) .withCreationTime(ledgerMetadataFormat.getCtime()) .withWriteQuorumSize(ledgerMetadataFormat.getQuorumSize()) .withEnsembleSize(ledgerMetadataFormat.getEnsembleSize()); ledgerMetadataFormat.getSegmentList().forEach(segment -> { ArrayList<BookieSocketAddress> addressArrayList = new ArrayList<>(); segment.getEnsembleMemberList().forEach(address -> { try { addressArrayList.add(new BookieSocketAddress(address)); } catch (IOException e) { log.error("Exception when create BookieSocketAddress. ", e); } }); builder.newEnsembleEntry(segment.getFirstEntryId(), addressArrayList); }); if (ledgerMetadataFormat.getCustomMetadataCount() > 0) { Map<String, byte[]> customMetadata = Maps.newHashMap(); ledgerMetadataFormat.getCustomMetadataList().forEach( entry -> customMetadata.put(entry.getKey(), entry.getValue().toByteArray())); builder.withCustomMetadata(customMetadata); } switch (ledgerMetadataFormat.getDigestType()) { case HMAC: builder.withDigestType(DigestType.MAC); break; case CRC32: builder.withDigestType(DigestType.CRC32); break; case CRC32C: builder.withDigestType(DigestType.CRC32C); break; case DUMMY: builder.withDigestType(DigestType.DUMMY); break; default: throw new IllegalArgumentException("Unable to convert digest type " + ledgerMetadataFormat.getDigestType()); } return builder.build(); }
Example #30
Source File: OffloadPrefixReadTest.java From pulsar with Apache License 2.0 | 4 votes |
@Override public List<BookieSocketAddress> getEnsembleAt(long entryId) { throw new UnsupportedOperationException("Pulsar shouldn't look at this"); }