Zookeeper's rapidly pooping its internal binary files all over our production environment. According to: http://zookeeper.apache.org/doc/r3.3.3/zookeeperAdmin.html and http://dougchang333.blogspot.com/2013/02/zookeeper-cleaning-logs-snapshots.html this is expected behavior and you must call org.apache.zookeeper.server.PurgeTxnLog regularly to rotate its poop.
So:
//BancoDeDados class
package kabashima.materiaisdeconstrucaoconcept.bancodedados;
import android.content.ContentValue`import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import kabashima.materiaisdeconstrucaoconcept.Contact;
public class BancoDeDados extends SQLiteOpenHelper {
// private static final int DATABASE_VERSION = 1;
//private static final String DATABASE_NAME = "contacts.db";
private static final String TABLE_NAME = "contacts";
private static final String COLUMN_ID = "id";
private static final String COLUMN_NOME = "nome";
private static final String COLUMN_EMAIL = "email";
private static final String COLUMN_SENHA = "senha";
SQLiteDatabase db;
private static final String TABLE_CREATE = "create table contacts(id integer primary key not null ," +
"nome text not null, email text not null, senha text not null);";
public BancoDeDados(Context context){
//super(context, DATABASE_NAME, null, DATABASE_VERSION);
super(context, "contacts.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(TABLE_CREATE);
db.execSQL( ScriptSQL.getCreateEstoqueProdutos());
this.db=db;
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String query = "DROP TABLE IF EXISTS" + TABLE_NAME;
db.execSQL(query);
this.onCreate(db);
}
public void insertContact(Contact c) {
db = this.getWritableDatabase();
ContentValues values = new ContentValues();
String query = "select * from contacts";
Cursor cursor = db.rawQuery(query, null);
int count = cursor.getCount();
values.put(COLUMN_ID, count);
values.put(COLUMN_NOME, c.getNome());
values.put(COLUMN_EMAIL, c.getEmail());
values.put(COLUMN_SENHA, c.getSenha());
db.insert(TABLE_NAME, null, values);
db.close();
}
public String searchPass(String nome){
db = this.getReadableDatabase();
String query = "select nome, senha from " + TABLE_NAME;
Cursor cursor = db.rawQuery(query, null);
String a,b;
b = "not found";
if(cursor.moveToFirst()){
do{
a = cursor.getString(0);
if(a.equals(nome))
{
b = cursor.getString(1);
break;
}
}while (cursor.moveToNext());
}
return b;
}
}
//AND THE SCRIPTSQL
package kabashima.materiaisdeconstrucaoconcept.bancodedados;
public static String getCreateEstoqueProdutos()
{
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append(" CREATE TABLE IF NOT EXISTS ESTOQUEPRODUTOS ( ");
sqlBuilder.append("_id INTEGER NOT NULL ");
sqlBuilder.append("PRIMARY KEY AUTOINCREMENT, ");
sqlBuilder.append("NOME VARCHAR (200), ");
sqlBuilder.append("MARCA VARCHAR (200), ");
sqlBuilder.append("LOJA VARCHAR (200), ");
sqlBuilder.append("ESTOQUE VARCHAR (10), ");
sqlBuilder.append("VALOR VARCHAR (30), ");
sqlBuilder.append(");");
return sqlBuilder.toString();
}
}
//RepositorioEstoque class
package kabashima.materiaisdeconstrucaoconcept.bancodedados.dominio;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ArrayAdapter;
public class RepositorioEstoque {
private SQLiteDatabase conn;
public RepositorioEstoque(SQLiteDatabase conn) {
this.conn = conn;
}
public void TesteInserirProdutos() {
for (int i = 0; i < 10; i++) {
ContentValues values = new ContentValues();
values.put("NOME", "JR");
conn.insertOrThrow("ESTOQUEPRODUTOS", null, values);
}
}
public ArrayAdapter<String> buscaEstoque(Context context)
{
ArrayAdapter<String> adpEstoque = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1);
Cursor cursor = conn.query("ESTOQUEPRODUTOS",null,null,null,null,null,null);
if (cursor.getCount() > 0)
{
do {
cursor.moveToFirst();
String nome = cursor.getString(1);
adpEstoque.add(nome);
} while (cursor.moveToNext());
}
return adpEstoque;
}
}
but I get:
% ls -l1rt /tmp/zookeeper/version-2/
total 314432
-rw-r--r-- 1 root root 67108880 Jun 26 18:00 log.1
-rw-r--r-- 1 root root 947092 Jun 26 18:00 snapshot.e99b
-rw-r--r-- 1 root root 67108880 Jun 27 05:00 log.e99d
-rw-r--r-- 1 root root 1620918 Jun 27 05:00 snapshot.1e266
... many more
% sudo java -cp zookeeper-3.4.6.jar::lib/jline-0.9.94.jar:lib/log4j-1.2.16.jar:lib/netty-3.7.0.Final.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:conf \
org.apache.zookeeper.server.PurgeTxnLog \
/tmp/zookeeper/version-2 /tmp/zookeeper/version-2 -n 3
Am I doing something wrong?
zookeeper-3.4.6/
答案 0 :(得分:10)
ZooKeeper现在具有3.4.0的Autopurge功能。看看https://zookeeper.apache.org/doc/trunk/zookeeperAdmin.html
它表示您可以使用autopurge.snapRetainCount
和autopurge.purgeInterval
的 autopurge.snapRetainCount 强>
3.4.0中的新增功能:启用后,ZooKeeper自动清除功能会分别在dataDir和dataLogDir中保留autopurge.snapRetainCount最新快照和相应的事务日志,并删除其余日志。默认为3.最小值为3.
<强> autopurge.purgeInterval 强>
3.4.0中的新功能:必须触发清除任务的时间间隔(以小时为单位)。设置为正整数(1和更高)以启用自动清除。默认为0。
答案 1 :(得分:4)
由于我没有通过Zookeeper听到修复,这是一个简单的解决方法:
* {
margin: 0;
padding: 0;
border: 0;
}
body {
padding: 10px;
background-color: #eee;
}
.popup {
box-shadow: 0 0 10px #ccc;
height: 240px;
width: 186px;
position: fixed;
top: 50px;
background-color: #fff;
}
.popup h1 {
font: bold 20px/3 Sans-Serif;
color: #fff;
padding: 0 20px;
background: url(http://thebusstopsherefoundation.com/images/bettis_wave.jpg)
no-repeat
-80px -90px/600px;
}
.popup header {
position: relative;
}
.corner-holder {
position: absolute;
right: 0;
top: 0;
height: 30px;
width: 60px;
overflow: hidden;
transform: translateY(-100%);
}
.corner-holder .corner,
.corner-holder .corner:before {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transform-origin: bottom left;
/* webkit trick to get rid of jagged edges */
-webkit-backface-visibility: hidden;
}
.corner-holder .corner {
overflow: hidden;
transform: skewX(-63.43deg);
}
.corner-holder .corner:before {
content: "";
background: url(http://thebusstopsherefoundation.com/images/bettis_wave.jpg)
no-repeat
-206px -60px/600px;
transform: skewX(63.43deg);
}
每天应该从一个cron job或jenkins运行一次,以防止zookeeper爆炸。