From dev-return-72740-archive-asf-public=cust-asf.ponee.io@zookeeper.apache.org Wed Sep 5 05:59:19 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 91CD6180668 for ; Wed, 5 Sep 2018 05:59:18 +0200 (CEST) Received: (qmail 13622 invoked by uid 500); 5 Sep 2018 03:59:17 -0000 Mailing-List: contact dev-help@zookeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zookeeper.apache.org Delivered-To: mailing list dev@zookeeper.apache.org Received: (qmail 13139 invoked by uid 99); 5 Sep 2018 03:59:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Sep 2018 03:59:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 32142E0969; Wed, 5 Sep 2018 03:59:16 +0000 (UTC) From: hanm To: dev@zookeeper.apache.org Reply-To: dev@zookeeper.apache.org References: In-Reply-To: Subject: [GitHub] zookeeper pull request #615: ZOOKEEPER-3137: add a utility to truncate logs ... Content-Type: text/plain Message-Id: <20180905035916.32142E0969@git1-us-west.apache.org> Date: Wed, 5 Sep 2018 03:59:16 +0000 (UTC) Github user hanm commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/615#discussion_r215129214 --- Diff: src/java/main/org/apache/zookeeper/server/util/LogChopper.java --- @@ -0,0 +1,152 @@ +/** + * 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 + * + * 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. + */ +package org.apache.zookeeper.server.util; + +import org.apache.jute.BinaryInputArchive; +import org.apache.jute.BinaryOutputArchive; +import org.apache.jute.Record; +import org.apache.zookeeper.server.persistence.FileHeader; +import org.apache.zookeeper.server.persistence.FileTxnLog; +import org.apache.zookeeper.txn.TxnHeader; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.EOFException; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.zip.Adler32; +import java.util.zip.Checksum; + +/** + * this class will chop the log at the specified zxid + */ +public class LogChopper { + public static void main(String args[]) { + if (args.length != 3) { + System.out.println("Usage: LogChopper zxid_to_chop_to txn_log_to_chop chopped_filename"); + System.out.println(" this program will read the txn_log_to_chop file and copy all the transactions"); + System.out.println(" from it up to (and including) the given zxid into chopped_filename."); + System.exit(1); + } + long zxid = Long.decode(args[0]); + String txnLog = args[1]; + String choppedLog = args[2]; + + int rc = 2; --- End diff -- We have recently added `ExitCode` enum, maybe use those for exit code? ---