From oak-issues-return-60988-archive-asf-public=cust-asf.ponee.io@jackrabbit.apache.org Thu Apr 5 15:46:05 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 CA660180677 for ; Thu, 5 Apr 2018 15:46:04 +0200 (CEST) Received: (qmail 88967 invoked by uid 500); 5 Apr 2018 13:46:03 -0000 Mailing-List: contact oak-issues-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: oak-dev@jackrabbit.apache.org Delivered-To: mailing list oak-issues@jackrabbit.apache.org Received: (qmail 88951 invoked by uid 99); 5 Apr 2018 13:46:03 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Apr 2018 13:46:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 1ED031A1148 for ; Thu, 5 Apr 2018 13:46:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -101.511 X-Spam-Level: X-Spam-Status: No, score=-101.511 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 3rDqNBYYVaJL for ; Thu, 5 Apr 2018 13:46:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id C7F455F640 for ; Thu, 5 Apr 2018 13:46:01 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id E68DEE09BC for ; Thu, 5 Apr 2018 13:46:00 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 40AE125623 for ; Thu, 5 Apr 2018 13:46:00 +0000 (UTC) Date: Thu, 5 Apr 2018 13:46:00 +0000 (UTC) From: "Vikas Saurabh (JIRA)" To: oak-issues@jackrabbit.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (OAK-7389) Mongo/FileBlobStore does not update timestamp for already existing blobs MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OAK-7389?page=3Dcom.atlassian.j= ira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D164269= 34#comment-16426934 ]=20 Vikas Saurabh edited comment on OAK-7389 at 4/5/18 1:45 PM: ------------------------------------------------------------ [~amitjain], these changes to your snippet makes it work: {noformat} // Check if it already exists? Document mongoBlob =3D new Document(); // <- use Document instead o= f MongoBlob which puts lastMod itself even if it's not set explicitly mongoBlob.append(MongoBlob.KEY_ID, id); mongoBlob.append(MongoBlob.KEY_DATA, data); mongoBlob.append(MongoBlob.KEY_LEVEL, level); Document updateBlob =3Dnew Document(MongoBlob.KEY_LAST_MOD, System.= currentTimeMillis()); // <- we don't want to set _id ... it's already part = of setOnInsert Document upsert =3D new Document(); upsert.append("$setOnInsert", mongoBlob) .append("$set", updateBlob); // TODO check the return value // TODO verify insert is fast if the entry already exists try { Bson query =3D getBlobQuery(id, -1); // <- negative last mod as= we don't want to query on last mod //Bson query =3D Filters.eq(MongoBlob.KEY_ID, id); FindOneAndUpdateOptions options =3D new FindOneAndUpdateOptions= ().upsert(true); // <- this change isn't required, but I don't think projec= ting _id is required {noformat} *EDIT*: Added these changes to [^OAK-7389-v2.patch]. was (Author: catholicon): [~amitjain], these changes to your snippet makes it work: {noformat} // Check if it already exists? Document mongoBlob =3D new Document(); // <- use Document instead o= f MongoBlob which puts lastMod itself even if it's not set explicitly mongoBlob.append(MongoBlob.KEY_ID, id); mongoBlob.append(MongoBlob.KEY_DATA, data); mongoBlob.append(MongoBlob.KEY_LEVEL, level); Document updateBlob =3Dnew Document(MongoBlob.KEY_LAST_MOD, System.= currentTimeMillis()); // <- we don't want to set _id ... it's already part = of setOnInsert Document upsert =3D new Document(); upsert.append("$setOnInsert", mongoBlob) .append("$set", updateBlob); // TODO check the return value // TODO verify insert is fast if the entry already exists try { Bson query =3D getBlobQuery(id, -1); // <- negative last mod as= we don't want to query on last mod //Bson query =3D Filters.eq(MongoBlob.KEY_ID, id); FindOneAndUpdateOptions options =3D new FindOneAndUpdateOptions= ().upsert(true); // <- this change isn't required, but I don't think projec= ting _id is required {noformat} > Mongo/FileBlobStore does not update timestamp for already existing blobs > ------------------------------------------------------------------------ > > Key: OAK-7389 > URL: https://issues.apache.org/jira/browse/OAK-7389 > Project: Jackrabbit Oak > Issue Type: Bug > Components: blob > Affects Versions: 1.2.14, 1.4.20, 1.8.2, 1.6.11 > Reporter: Amit Jain > Assignee: Amit Jain > Priority: Critical > Fix For: 1.2.30 > > Attachments: OAK-7389-v1.patch, OAK-7389-v2.patch > > > MongoBlobStore uses uses the {{insert}} call and ignores any exceptions w= hich means any existing value won't be updated. > {code:java} > @Override > protected void storeBlock(byte[] digest, int level, byte[] data) thro= ws IOException { > String id =3D StringUtils.convertBytesToHex(digest); > cache.put(id, data); > // Check if it already exists? > MongoBlob mongoBlob =3D new MongoBlob(); > mongoBlob.setId(id); > mongoBlob.setData(data); > mongoBlob.setLevel(level); > mongoBlob.setLastMod(System.currentTimeMillis()); > // TODO check the return value > // TODO verify insert is fast if the entry already exists > try { > getBlobCollection().insertOne(mongoBlob); > } catch (DuplicateKeyException e) { > // the same block was already stored before: ignore > } catch (MongoException e) { > if (e.getCode() =3D=3D DUPLICATE_KEY_ERROR_CODE) { > // the same block was already stored before: ignore > } else { > throw new IOException(e.getMessage(), e); > } > } > } > {code} > =C2=A0FileBlobStore also returns if there's a file already existing witho= ut updating the timestamp > {code:java} > @Override > protected synchronized void storeBlock(byte[] digest, int level, byte= [] data) throws IOException { > File f =3D getFile(digest, false); > if (f.exists()) { > return; > } > ......... > {code} > The above would cause data loss in DSGC if there are updates to the blob = blocks which are re-surrected (stored again at the time of DSGC) because th= e timestamp would never have been modified. > =C2=A0 > cc/ [~tmueller], [~mreutegg], [~chetanm], [~catholicon] -- This message was sent by Atlassian JIRA (v7.6.3#76005)