Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.hadoop.hdds.utils.db;

import java.io.IOException;
import com.google.common.primitives.Shorts;

/**
* Codec to convert Short to/from byte array.
*/
public class ShortCodec implements Codec<Short> {

@Override
public byte[] toPersistedFormat(Short object) throws IOException {
return Shorts.toByteArray(object);
}

@Override
public Short fromPersistedFormat(byte[] rawData) throws IOException {
return Shorts.fromByteArray(rawData);
}

@Override
public Short copyObject(Short object) {
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix;
import org.apache.hadoop.ozone.recon.spi.ContainerDBServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager;
import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl;
import org.apache.ozone.test.GenericTestUtils;
import org.junit.After;
Expand Down Expand Up @@ -130,10 +130,10 @@ public void testReconGetsSnapshotFromLeader() throws Exception {
// Sync data to Recon
impl.syncDataFromOM();

ContainerDBServiceProvider containerDBServiceProvider =
cluster.getReconServer().getContainerDBServiceProvider();
ReconContainerMetadataManager reconContainerMetadataManager =
cluster.getReconServer().getReconContainerMetadataManager();
TableIterator iterator =
containerDBServiceProvider.getContainerTableIterator();
reconContainerMetadataManager.getContainerTableIterator();
String reconKeyPrefix = null;
while (iterator.hasNext()) {
Table.KeyValue<ContainerKeyPrefix, Integer> keyValue =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ private ReconConstants() {
+ PIPELINE_DB_SUFFIX;
public static final String RECON_SCM_NODE_DB =
"recon-node.db";
// 1125899906842624L = 1PB
public static final long MAX_FILE_SIZE_UPPER_BOUND = 1125899906842624L;
public static final long MIN_FILE_SIZE_UPPER_BOUND = 1024L;
// 41 bins
public static final int NUM_OF_BINS = (int) Math.ceil(Math.log(
(double) MAX_FILE_SIZE_UPPER_BOUND / MIN_FILE_SIZE_UPPER_BOUND) /
Math.log(2)) + 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.protocol.StorageContainerLocationProtocol;
import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
import org.apache.hadoop.hdds.utils.db.DBStore;
import org.apache.hadoop.ozone.om.OMMetadataManager;
import org.apache.hadoop.ozone.om.protocol.OzoneManagerProtocol;
import org.apache.hadoop.ozone.om.protocolPB.OmTransport;
Expand All @@ -38,12 +37,14 @@
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
import org.apache.hadoop.ozone.recon.recovery.ReconOmMetadataManagerImpl;
import org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade;
import org.apache.hadoop.ozone.recon.spi.ContainerDBServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager;
import org.apache.hadoop.ozone.recon.spi.OzoneManagerServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ContainerDBServiceProviderImpl;
import org.apache.hadoop.ozone.recon.spi.impl.ReconContainerMetadataManagerImpl;
import org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl;
import org.apache.hadoop.ozone.recon.spi.impl.ReconContainerDBProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ReconDBProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ReconNamespaceSummaryManagerImpl;
import org.apache.hadoop.ozone.recon.spi.impl.StorageContainerServiceProviderImpl;
import org.apache.hadoop.ozone.recon.tasks.ContainerKeyMapperTask;
import org.apache.hadoop.ozone.recon.tasks.FileSizeCountTask;
Expand Down Expand Up @@ -85,15 +86,16 @@ public class ReconControllerModule extends AbstractModule {
protected void configure() {
bind(OzoneConfiguration.class).toProvider(ConfigurationProvider.class);
bind(ReconHttpServer.class).in(Singleton.class);
bind(DBStore.class)
.toProvider(ReconContainerDBProvider.class).in(Singleton.class);
bind(ReconDBProvider.class).in(Singleton.class);
bind(ReconOMMetadataManager.class)
.to(ReconOmMetadataManagerImpl.class);
bind(OMMetadataManager.class).to(ReconOmMetadataManagerImpl.class);

bind(ContainerHealthSchemaManager.class).in(Singleton.class);
bind(ContainerDBServiceProvider.class)
.to(ContainerDBServiceProviderImpl.class).in(Singleton.class);
bind(ReconContainerMetadataManager.class)
.to(ReconContainerMetadataManagerImpl.class).in(Singleton.class);
bind(ReconNamespaceSummaryManager.class)
.to(ReconNamespaceSummaryManagerImpl.class).in(Singleton.class);
bind(OzoneManagerServiceProvider.class)
.to(OzoneManagerServiceProviderImpl.class).in(Singleton.class);
bind(ReconUtils.class).in(Singleton.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager;
import org.apache.hadoop.hdds.utils.HddsServerUtil;
import org.apache.hadoop.ozone.OzoneSecurityUtil;
import org.apache.hadoop.ozone.recon.spi.ContainerDBServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager;
import org.apache.hadoop.ozone.recon.spi.OzoneManagerServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconNamespaceSummaryManager;
import org.apache.hadoop.ozone.recon.spi.StorageContainerServiceProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ReconDBProvider;
import org.apache.hadoop.ozone.util.OzoneVersionInfo;
import org.apache.hadoop.security.SecurityUtil;
import org.apache.hadoop.security.UserGroupInformation;
Expand All @@ -56,8 +58,10 @@ public class ReconServer extends GenericCli {
private Injector injector;

private ReconHttpServer httpServer;
private ContainerDBServiceProvider containerDBServiceProvider;
private ReconContainerMetadataManager reconContainerMetadataManager;
private OzoneManagerServiceProvider ozoneManagerServiceProvider;
private ReconDBProvider reconDBProvider;
private ReconNamespaceSummaryManager reconNamespaceSummaryManager;
private OzoneStorageContainerManager reconStorageContainerManager;
private OzoneConfiguration configuration;

Expand Down Expand Up @@ -93,8 +97,11 @@ protected void configureServlets() {
LOG.info("Initializing Recon server...");
try {
loginReconUserIfSecurityEnabled(configuration);
this.containerDBServiceProvider =
injector.getInstance(ContainerDBServiceProvider.class);
this.reconDBProvider = injector.getInstance(ReconDBProvider.class);
this.reconContainerMetadataManager =
injector.getInstance(ReconContainerMetadataManager.class);
this.reconNamespaceSummaryManager =
injector.getInstance(ReconNamespaceSummaryManager.class);

ReconSchemaManager reconSchemaManager =
injector.getInstance(ReconSchemaManager.class);
Expand Down Expand Up @@ -159,8 +166,8 @@ public void stop() throws Exception {
if (ozoneManagerServiceProvider != null) {
ozoneManagerServiceProvider.stop();
}
if (containerDBServiceProvider != null) {
containerDBServiceProvider.close();
if (reconDBProvider != null) {
reconDBProvider.close();
}
isStarted = false;
}
Expand Down Expand Up @@ -234,8 +241,8 @@ public StorageContainerServiceProvider getStorageContainerServiceProvider() {
}

@VisibleForTesting
public ContainerDBServiceProvider getContainerDBServiceProvider() {
return containerDBServiceProvider;
public ReconContainerMetadataManager getReconContainerMetadataManager() {
return reconContainerMetadataManager;
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import org.apache.hadoop.ozone.recon.persistence.ContainerHealthSchemaManager;
import org.apache.hadoop.ozone.recon.recovery.ReconOMMetadataManager;
import org.apache.hadoop.ozone.recon.scm.ReconContainerManager;
import org.apache.hadoop.ozone.recon.spi.ContainerDBServiceProvider;
import org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager;
import org.hadoop.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates;
import org.hadoop.ozone.recon.schema.tables.pojos.UnhealthyContainers;

Expand All @@ -79,7 +79,7 @@
public class ContainerEndpoint {

@Inject
private ContainerDBServiceProvider containerDBServiceProvider;
private ReconContainerMetadataManager reconContainerMetadataManager;

@Inject
private ReconOMMetadataManager omMetadataManager;
Expand Down Expand Up @@ -113,8 +113,9 @@ public Response getContainers(
Map<Long, ContainerMetadata> containersMap;
long containersCount;
try {
containersMap = containerDBServiceProvider.getContainers(limit, prevKey);
containersCount = containerDBServiceProvider.getCountForContainers();
containersMap =
reconContainerMetadataManager.getContainers(limit, prevKey);
containersCount = reconContainerMetadataManager.getCountForContainers();
} catch (IOException ioEx) {
throw new WebApplicationException(ioEx,
Response.Status.INTERNAL_SERVER_ERROR);
Expand Down Expand Up @@ -147,7 +148,7 @@ public Response getKeysForContainer(
long totalCount;
try {
Map<ContainerKeyPrefix, Integer> containerKeyPrefixMap =
containerDBServiceProvider.getKeyPrefixesForContainer(containerID,
reconContainerMetadataManager.getKeyPrefixesForContainer(containerID,
prevKeyPrefix);

// Get set of Container-Key mappings for given containerId.
Expand Down Expand Up @@ -204,7 +205,7 @@ public Response getKeysForContainer(
}

totalCount =
containerDBServiceProvider.getKeyCountForContainer(containerID);
reconContainerMetadataManager.getKeyCountForContainer(containerID);
} catch (IOException ioEx) {
throw new WebApplicationException(ioEx,
Response.Status.INTERNAL_SERVER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.hadoop.ozone.recon.api.types;

import org.apache.hadoop.ozone.recon.ReconConstants;

import java.util.Arrays;

/**
* Class to encapsulate namespace metadata summaries from OM.
*/

public class NSSummary {
private int numOfFiles;
private int sizeOfFiles;
private int[] fileSizeBucket;

public NSSummary() {
this.numOfFiles = 0;
this.sizeOfFiles = 0;
this.fileSizeBucket = new int[ReconConstants.NUM_OF_BINS];
}

public NSSummary(int numOfFiles, int sizeOfFiles, int[] bucket) {
this.numOfFiles = numOfFiles;
this.sizeOfFiles = sizeOfFiles;
setFileSizeBucket(bucket);
}

public int getNumOfFiles() {
return numOfFiles;
}

public int getSizeOfFiles() {
return sizeOfFiles;
}

public int[] getFileSizeBucket() {
return Arrays.copyOf(this.fileSizeBucket, ReconConstants.NUM_OF_BINS);
}

public void setNumOfFiles(int numOfFiles) {
this.numOfFiles = numOfFiles;
}

public void setSizeOfFiles(int sizeOfFiles) {
this.sizeOfFiles = sizeOfFiles;
}

public void setFileSizeBucket(int[] fileSizeBucket) {
this.fileSizeBucket = Arrays.copyOf(
fileSizeBucket, ReconConstants.NUM_OF_BINS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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 org.apache.hadoop.ozone.recon.codec;

import org.apache.hadoop.hdds.utils.db.IntegerCodec;
import org.apache.hadoop.hdds.utils.db.ShortCodec;
import org.apache.hadoop.ozone.recon.ReconConstants;
import org.apache.hadoop.ozone.recon.api.types.NSSummary;
import org.apache.hadoop.hdds.utils.db.Codec;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.IOException;

/**
* Codec for Namespace Summary.
*/
public class NSSummaryCodec implements Codec<NSSummary> {

private final Codec<Integer> integerCodec = new IntegerCodec();
private final Codec<Short> shortCodec = new ShortCodec();
// 2 int fields + 41-length int array
private static final int NUM_OF_INTS = 2 + ReconConstants.NUM_OF_BINS;

@Override
public byte[] toPersistedFormat(NSSummary object) throws IOException {
final int sizeOfRes = NUM_OF_INTS * Integer.BYTES + Short.BYTES;
ByteArrayOutputStream out = new ByteArrayOutputStream(sizeOfRes);
out.write(integerCodec.toPersistedFormat(object.getNumOfFiles()));
out.write(integerCodec.toPersistedFormat(object.getSizeOfFiles()));
out.write(shortCodec.toPersistedFormat((short)ReconConstants.NUM_OF_BINS));
int[] fileSizeBucket = object.getFileSizeBucket();
for (int i = 0; i < ReconConstants.NUM_OF_BINS; ++i) {
out.write(integerCodec.toPersistedFormat(fileSizeBucket[i]));
}
return out.toByteArray();
}

@Override
public NSSummary fromPersistedFormat(byte[] rawData) throws IOException {
assert(rawData.length == NUM_OF_INTS * Integer.BYTES + Short.BYTES);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(rawData));
NSSummary res = new NSSummary();
res.setNumOfFiles(in.readInt());
res.setSizeOfFiles(in.readInt());
short len = in.readShort();
assert(len == (short) ReconConstants.NUM_OF_BINS);
int[] fileSizeBucket = new int[len];
for (int i = 0; i < len; ++i) {
fileSizeBucket[i] = in.readInt();
}
res.setFileSizeBucket(fileSizeBucket);
return res;
}

@Override
public NSSummary copyObject(NSSummary object) {
NSSummary copy = new NSSummary();
copy.setNumOfFiles(object.getNumOfFiles());
copy.setSizeOfFiles(object.getSizeOfFiles());
copy.setFileSizeBucket(object.getFileSizeBucket());
return copy;
}
}
Loading