Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adding a configuration class. #2

Merged
merged 1 commit into from

2 participants

@fpj

The configuration class, called TSOServerConfig, holds values of parameters needed across different classes. The general idea is to simply have all parameter values in a single place instead of spread throughout the code.

@dgomezferro dgomezferro merged commit c46227a into yahoo:master
@francisco-perez-sorrosal francisco-perez-sorrosal referenced this pull request from a commit
Francisco Perez-Sorrosal [SLINGCSCF-1689] Fix: Tables not flushed when updating shadow cells
Problem description: When autoflush is off and TTables are not closed after
transaction commit, a large number of cells without their corresponding
shadow cells may appear.

When the HBaseTransactionManager commits a TX, it:
1) writes the commit table entry for the Tx
2) updates shadow cells
3) erases the commit table entry

Before this fix, in step #2 the tables were not flushed, so some shadow cells
were not be written to HBase before the commit table entry was erased.

Change-Id: I8fceb0695ca8243b8f33e4ffa759ca33b7114757
1a9c9cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2012
  1. @fpj

    Adding a configuration class. -F

    fpj authored
This page is out of date. Refresh to see the latest.
View
4 src/main/java/com/yahoo/omid/tso/TSOHandler.java
@@ -421,7 +421,9 @@ else if (sharedState.uncommited.isUncommited(msg.queryTimestamp))
public void flush() {
synchronized (sharedState) {
- LOG.info("Adding record");
+ if(LOG.isDebugEnabled()){
+ LOG.debug("Adding record, size: " + sharedState.baos.size());
+ }
sharedState.addRecord(sharedState.baos.toByteArray(), new AddRecordCallback() {
@Override
public void addRecordComplete(int rc, Object ctx) {
View
33 src/main/java/com/yahoo/omid/tso/TSOServer.java
@@ -61,34 +61,21 @@
private static final Log LOG = LogFactory.getLog(BookKeeperStateBuilder.class);
private TSOState state;
- private int port;
- private int batch;
- private int ensemble;
- private int quorum;
- private String zkservers;
+ private TSOServerConfig config;
private boolean finish;
private Object lock;
- public TSOServer(int port, int batch, int ensemble, int quorum, String zkservers) {
+ public TSOServer() {
super();
- this.port = port;
- this.batch = batch;
- this.ensemble = ensemble;
- this.quorum = quorum;
- this.zkservers = zkservers;
- System.setProperty("ZKSERVERS", zkservers);
+ this.config = TSOServerConfig.configFactory();
this.finish = false;
this.lock = new Object();
}
-
- public TSOServer(int port, int batch) {
+
+ public TSOServer(TSOServerConfig config) {
super();
- this.port = port;
- this.batch = batch;
- this.ensemble = -1;
- this.quorum = -1;
- this.zkservers = "";
+ this.config = config;
this.finish = false;
this.lock = new Object();
@@ -119,7 +106,7 @@ public static void main(String[] args) throws Exception {
int ensSize = Integer.parseInt(args[2]), qSize = Integer.parseInt(args[3]);
String zkservers = args[4];
- new TSOServer(port, batch, ensSize, qSize, zkservers).run();
+ new TSOServer(TSOServerConfig.configFactory(port, batch, (zkservers != null), ensSize, qSize, zkservers)).run();
}
@Override
@@ -149,7 +136,7 @@ public void run() {
LOG.error("Couldn't build state");
return;
}
- TSOState.BATCH_SIZE = batch;
+ TSOState.BATCH_SIZE = config.getBatchSize();
System.out.println("PARAM MAX_ITEMS: " + TSOState.MAX_ITEMS);
System.out.println("PARAM BATCH_SIZE: " + TSOState.BATCH_SIZE);
System.out.println("PARAM LOAD_FACTOR: " + TSOState.LOAD_FACTOR);
@@ -170,7 +157,7 @@ public void run() {
// Create the monitor
ThroughputMonitor monitor = new ThroughputMonitor(state);
// Add the parent channel to the group
- Channel channel = bootstrap.bind(new InetSocketAddress(port));
+ Channel channel = bootstrap.bind(new InetSocketAddress(config.getPort())));
channelGroup.add(channel);
// Compacter handler
@@ -196,7 +183,7 @@ public ChannelPipeline getPipeline() throws Exception {
comBootstrap.setOption("child.reuseAddress", true);
comBootstrap.setOption("child.connectTimeoutMillis", 100);
comBootstrap.setOption("readWriteFair", true);
- channel = comBootstrap.bind(new InetSocketAddress(port + 1));
+ channel = comBootstrap.bind(new InetSocketAddress(config.getPort() + 1));
// Starts the monitor
monitor.start();
View
91 src/main/java/com/yahoo/omid/tso/TSOServerConfig.java
@@ -0,0 +1,91 @@
+/**
+ * Copyright (c) 2011 Yahoo! Inc. All rights reserved.
+ *
+ * Licensed 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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. See accompanying LICENSE file.
+ */
+
+package com.yahoo.omid.tso;
+
+/**
+ * Holds the configuration parameters of a TSO server instance.
+ *
+ */
+public class TSOServerConfig {
+
+ private static TSOServerConfig config;
+
+ static public TSOServerConfig configFactory(){
+ if(config == null){
+ config = new TSOServerConfig();
+ }
+
+ return config;
+ }
+
+ static public TSOServerConfig configFactory(int port, int batch, boolean recoveryEnabled, int ensSize, int qSize, String zkservers){
+ if(config == null){
+ config = new TSOServerConfig(port, batch, recoveryEnabled, ensSize, qSize, zkservers);
+ }
+
+ return config;
+ }
+
+ private int port;
+ private int batch;
+ private boolean recoveryEnabled;
+ private String zkServers;
+ private int ensemble;
+ private int quorum;
+
+ TSOServerConfig(){
+ this.port = Integer.parseInt(System.getProperty("PORT", "1234"));
+ this.batch = Integer.parseInt(System.getProperty("batch", "0"));
+ this.recoveryEnabled = Boolean.parseBoolean(System.getProperty("RECOVERABLE", "false"));
+ this.zkServers = System.getProperty("ZKSERVERS");
+ this.ensemble = Integer.parseInt(System.getProperty("ENSEMBLE", "3"));
+ this.quorum = Integer.parseInt(System.getProperty("QUORUM", "2"));
+ }
+
+ TSOServerConfig(int port, int batch, boolean recoveryEnabled, int ensemble, int quorum, String zkServers){
+ this.port = port;
+ this.batch = batch;
+ this.recoveryEnabled = Boolean.parseBoolean(System.getProperty("RECOVERABLE", "false"));
+ this.zkServers = System.getProperty("ZKSERVERS");
+ this.ensemble = Integer.parseInt(System.getProperty("ENSEMBLE", "3"));
+ this.quorum = Integer.parseInt(System.getProperty("QUORUM", "2"));
+ }
+
+ public int getPort(){
+ return port;
+ }
+
+ public int getBatchSize(){
+ return batch;
+ }
+
+ public boolean isRecoveryEnabled(){
+ return recoveryEnabled;
+ }
+
+ public String getZkServers(){
+ return zkServers;
+ }
+
+ public int getEnsembleSize(){
+ return ensemble;
+ }
+
+ public int getQuorumSize(){
+ return quorum;
+ }
+}
View
6 src/main/java/com/yahoo/omid/tso/persistence/BookKeeperStateLogger.java
@@ -46,6 +46,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.yahoo.omid.tso.TSOHandler;
+import com.yahoo.omid.tso.TSOServerConfig;
import com.yahoo.omid.tso.persistence.StateLogger;
import com.yahoo.omid.tso.persistence.LoggerAsyncCallback.LoggerInitCallback;
import com.yahoo.omid.tso.persistence.LoggerAsyncCallback.BuilderInitCallback;
@@ -159,6 +160,8 @@ public void process(WatchedEvent event){
@Override
public void initialize(final LoggerInitCallback cb, Object ctx)
throws LoggerException {
+ TSOServerConfig config = TSOServerConfig.configFactory();
+
/*
* Create new ledger for adding records
*/
@@ -169,7 +172,8 @@ public void initialize(final LoggerInitCallback cb, Object ctx)
throw new LoggerException.BKOpFailedException();
}
- bk.asyncCreateLedger(3, 2,
+ bk.asyncCreateLedger(config.getEnsembleSize(),
+ config.getQuorumSize(),
BookKeeper.DigestType.CRC32,
"flavio was here".getBytes(),
new CreateCallback(){
Something went wrong with that request. Please try again.