8000 HDDS-1232 : Recon Container DB service definition. by avijayanhwx · Pull Request #569 · apache/hadoop · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

HDDS-1232 : Recon Container DB service definition. #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
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
Expand Up @@ -61,4 +61,9 @@ public void seekToFirst() {
public void seekToLast() {
levelDBIterator.seekToLast();
}

@Override
public void prefixSeek(byte[] prefix) {
levelDBIterator.seek(prefix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ public interface MetaStoreIterator<T> extends Iterator<T> {
*/
void seekToLast();

/**
* seek with prefix.
*/
void prefixSeek(byte[] prefix);

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public void seekToLast() {
rocksDBIterator.seekToLast();
}

@Override
public void prefixSeek(byte[] prefix) {
rocksDBIterator.seek(prefix);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,58 @@ public void testIterator() throws Exception {

}


@Test
public void testIteratorPrefixSeek() throws Exception {
Configuration conf = new OzoneConfiguration();
conf.set(OzoneConfigKeys.OZONE_METADATA_STORE_IMPL, storeImpl);
File dbDir = GenericTestUtils.getRandomizedTestDir();
MetadataStore dbStore = MetadataStoreBuilder.newBuilder()
.setConf(conf)
.setCreateIfMissing(true)
.setDbFile(dbDir)
.build();

for (int i = 0; i < 5; i++) {
dbStore.put(getBytes("a" + i), getBytes("a-value" + i));
}

for (int i = 0; i < 5; i++) {
dbStore.put(getBytes("b" + i), getBytes("b-value" + i));
}

for (int i = 0; i < 5; i++) {
dbStore.put(getBytes("c" + i), getBytes("c-value" + i));
}

for (int i = 5; i < 10; i++) {
dbStore.put(getBytes("b" + i), getBytes("b-value" + i));
}

for (int i = 5; i < 10; i++) {
dbStore.put(getBytes("a" + i), getBytes("a-value" + i));
}


MetaStoreIterator<KeyValue> metaStoreIterator = dbStore.iterator();
metaStoreIterator.prefixSeek(getBytes("b"));
int i = 0;
while (metaStoreIterator.hasNext()) {
KeyValue val = metaStoreIterator.next();
String key = getString(val.getKey());
if (key.startsWith("b")) {
assertEquals("b-value" + i, getString(val.getValue()));
} else {
break;
}
i++;
}
assertTrue(i == 10);
dbStore.close();
dbStore.destroy();
FileUtils.deleteDirectory(dbDir);
}

@Test
public void testMetaStoreConfigDifferentFromType() throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,29 @@ public static void releaseConnection(HttpRequestBase request) {
* @return
*/
public static File getScmDbDir(Configuration conf) {
final Collection<String> metadirs = conf.getTrimmedStringCollection(
ScmConfigKeys.OZONE_SCM_DB_DIRS);

File metadataDir = getDirWithFallBackToOzoneMetadata(conf, ScmConfigKeys
.OZONE_SCM_DB_DIRS, "SCM");
if (metadataDir != null) {
return metadataDir;
}

LOG.warn("{} is not configured. We recommend adding this setting. " +
"Falling back to {} instead.",
ScmConfigKeys.OZONE_SCM_DB_DIRS, HddsConfigKeys.OZONE_METADATA_DIRS);
return getOzoneMetaDirPath(conf);
}

public static File getDirWithFallBackToOzoneMetadata(Configuration conf,
String key,
String componentName) {
final Collection<String> metadirs = conf.getTrimmedStringCollection(key);

if (metadirs.size() > 1) {
throw new IllegalArgumentException(
"Bad config setting " + ScmConfigKeys.OZONE_SCM_DB_DIRS +
". SCM does not support multiple metadata dirs currently");
"Bad config setting " + key +
". " + componentName +
" does not support multiple metadata dirs currently");
}

if (metadirs.size() == 1) {
Expand All @@ -143,11 +159,7 @@ public static File getScmDbDir(Configuration conf) {
}
return dbDirPath;
}

LOG.warn("{} is not configured. We recommend adding this setting. " +
"Falling back to {} instead.",
ScmConfigKeys.OZONE_SCM_DB_DIRS, HddsConfigKeys.OZONE_METADATA_DIRS);
return getOzoneMetaDirPath(conf);
return null;
}

/**
Expand Down
13 changes: 12 additions & 1 deletion hadoop-ozone/ozone-recon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</parent>
<name>Apache Hadoo 9E7A p Ozone Recon</name>
<modelVersion>4.0.0</modelVersion>
<artifactId>ozone-recon</artifactId>
<artifactId>hadoop-ozone-ozone-recon</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.hadoop</groupId>
Expand Down Expand Up @@ -50,5 +50,16 @@
<artifactId>guice-assistedinject</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
package org.apache.hadoop.ozone.recon;

import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.recon.spi.MetadataStoreProvider;
import org.apache.hadoop.ozone.recon.spi.ContainerDBServiceProvider;
import org.apache.hadoop.ozone.recon.spi.impl.ContainerDBServiceProviderImpl;
import org.apache.hadoop.utils.MetadataStore;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
Expand All @@ -30,6 +34,9 @@ public class ReconControllerModule extends AbstractModule {
protected void configure() {
bind(OzoneConfiguration.class).toProvider(OzoneConfigurationProvider.class);
bind(ReconHttpServer.class).in(Singleton.class);
bind(MetadataStore.class).toProvider(MetadataStoreProvider.class);
bind(ContainerDBServiceProvider.class)
.to(ContainerDBServiceProviderImpl.class);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,52 +37,52 @@ public class ReconHttpServer extends BaseHttpServer {

@Override
protected String getHttpAddressKey() {
return ReconServerConfiguration.OZONE_RECON_HTTP_ADDRESS_KEY;
return ReconServerConfigKeys.OZONE_RECON_HTTP_ADDRESS_KEY;
}

@Override
protected String getHttpsAddressKey() {
return ReconServerConfiguration.OZONE_RECON_HTTPS_ADDRESS_KEY;
return ReconServerConfigKeys.OZONE_RECON_HTTPS_ADDRESS_KEY;
}

@Override
protected String getHttpBindHostKey() {
return ReconServerConfiguration.OZONE_RECON_HTTP_BIND_HOST_KEY;
return ReconServerConfigKeys.OZONE_RECON_HTTP_BIND_HOST_KEY;
}

@Override
protected String getHttpsBindHostKey() {
return ReconServerConfiguration.OZONE_RECON_HTTPS_BIND_HOST_KEY;
return ReconServerConfigKeys.OZONE_RECON_HTTPS_BIND_HOST_KEY;
}

@Override
protected String getBindHostDefault() {
return ReconServerConfiguration.OZONE_RECON_HTTP_BIND_HOST_DEFAULT;
return ReconServerConfigKeys.OZONE_RECON_HTTP_BIND_HOST_DEFAULT;
}

@Override
protected int getHttpBindPortDefault() {
return ReconServerConfiguration.OZONE_RECON_HTTP_BIND_PORT_DEFAULT;
return ReconServerConfigKeys.OZONE_RECON_HTTP_BIND_PORT_DEFAULT;
}

@Override
protected int getHttpsBindPortDefault() {
return ReconServerConfiguration.OZONE_RECON_HTTPS_BIND_PORT_DEFAULT;
return ReconServerConfigKeys.OZONE_RECON_HTTPS_BIND_PORT_DEFAULT;
}

@Override
protected String getKeytabFile() {
return ReconServerConfiguration.OZONE_RECON_KEYTAB_FILE;
return ReconServerConfigKeys.OZONE_RECON_KEYTAB_FILE;
}

@Override
protected String getSpnegoPrincipal() {
return ReconServerConfiguration
return ReconServerConfigKeys
.OZONE_RECON_WEB_AUTHENTICATION_KERBEROS_PRINCIPAL;
}

@Override
protected String getEnabledKey() {
return ReconServerConfiguration.OZONE_RECON_HTTP_ENABLED_KEY;
return ReconServerConfigKeys.OZONE_RECON_HTTP_ENABLED_KEY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.ozone.recon;

import static org.apache.hadoop.ozone.OzoneConsts.CONTAINER_DB_SUFFIX;

import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;

Expand All @@ -25,7 +27,7 @@
*/
@InterfaceAudience.Public
@InterfaceStability.Unstable
public final class ReconServerConfiguration {
public final class ReconServerConfigKeys {

public static final String OZONE_RECON_HTTP_ENABLED_KEY =
"ozone.recon.http.enabled";
Expand All @@ -48,9 +50,17 @@ public final class ReconServerConfiguration {
public static final String OZONE_RECON_DOMAIN_NAME =
"ozone.recon.domain.name";

public static final String OZONE_RECON_CONTAINER_DB_CACHE_SIZE_MB =
"ozone.recon.container.db.cache.size.mb";
public static final int OZONE_RECON_CONTAINER_DB_CACHE_SIZE_DEFAULT = 128;

public static final String OZONE_RECON_DB_DIRS = "ozone.recon.db.dirs";
public static final String RECON_CONTAINER_DB = "recon-" +
CONTAINER_DB_SUFFIX;

/**
* Private constructor for utility class.
*/
private ReconServerConfiguration() {
private ReconServerConfigKeys() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 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;

/**
* Class to encapsulate the Key information needed for the Recon container DB.
* Currently, it is containerId and key prefix.
*/
public class ContainerKeyPrefix {

private long containerId;
private String keyPrefix;

public ContainerKeyPrefix(long containerId, String keyPrefix) {
this.containerId = containerId;
this.keyPrefix = keyPrefix;
}

public long getContainerId() {
return containerId;
}

public void setContainerId(long containerId) {
this.containerId = containerId;
}

public String getKeyPrefix() {
return keyPrefix;
}

public void setKeyPrefix(String keyPrefix) {
this.keyPrefix = keyPrefix;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* 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.spi;

import java.io.IOException;
import java.util.Map;

import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix;

/**
* The Recon Container DB Service interface.
*/
@InterfaceStability.Evolving
public interface ContainerDBServiceProvider {

/**
* Store the container to Key prefix mapping into the Recon Container DB.
*
* @param containerKeyPrefix the containerId, key-prefix tuple.
* @param count Count of Keys with that prefix.
*/
void storeContainerKeyMapping(ContainerKeyPrefix containerKeyPrefix,
Integer count) throws IOException;

/**
* Get the stored key prefix count for the given containerId, key prefix.
*
* @param containerKeyPrefix the containerId, key-prefix tuple.
* @return count of keys with that prefix.
*/
Integer getCountForForContainerKeyPrefix(
ContainerKeyPrefix containerKeyPrefix) throws IOException;

/**
* Get the stored key prefixes for the given containerId.
*
* @param containerId the given containerId.
* @return Map of Key prefix -> count.
*/
Map<String, Integer> getKeyPrefixesForContainer(long containerId);
}
Loading
0