Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6ED30200BE2 for ; Thu, 1 Dec 2016 02:37:55 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 6D971160B19; Thu, 1 Dec 2016 01:37:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E0190160B13 for ; Thu, 1 Dec 2016 02:37:54 +0100 (CET) Received: (qmail 51835 invoked by uid 500); 1 Dec 2016 01:37:54 -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 51813 invoked by uid 99); 1 Dec 2016 01:37:53 -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; Thu, 01 Dec 2016 01:37:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 99C22E04BB; Thu, 1 Dec 2016 01:37:53 +0000 (UTC) From: lvfangmin To: dev@zookeeper.apache.org Reply-To: dev@zookeeper.apache.org References: In-Reply-To: Subject: [GitHub] zookeeper pull request #117: ZOOKEEPER-2325: Data inconsistency if all snaps... Content-Type: text/plain Message-Id: <20161201013753.99C22E04BB@git1-us-west.apache.org> Date: Thu, 1 Dec 2016 01:37:53 +0000 (UTC) archived-at: Thu, 01 Dec 2016 01:37:55 -0000 Github user lvfangmin commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/117#discussion_r90368114 --- Diff: src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java --- @@ -165,8 +165,22 @@ public File getSnapDir() { */ public long restore(DataTree dt, Map sessions, PlayBackListener listener) throws IOException { - snapLog.deserialize(dt, sessions); + long deserializeResult = snapLog.deserialize(dt, sessions); FileTxnLog txnLog = new FileTxnLog(dataDir); + if (-1L == deserializeResult) { + /* this means that we couldn't find any snapshot, so we need to + * initialize an empty database */ + if (txnLog.getLastLoggedZxid() != -1) { + throw new IOException( + "No snapshot found, but there are log entries. " + + "Something is broken!"); + } + /* TODO: (br33d) we should either put a ConcurrentHashMap on restore() + * or use Map on save() */ + save(dt, (ConcurrentHashMap)sessions); --- End diff -- n00b question, why we need to save here? I saw there is potential that the follower will sync with with leader just to send over the empty snapshot. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---