<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[osnap - Medium]]></title>
        <description><![CDATA[ThinAir Engineering Blog - Medium]]></description>
        <link>https://medium.com/osnap?source=rss----e71cfaf8e398---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>osnap - Medium</title>
            <link>https://medium.com/osnap?source=rss----e71cfaf8e398---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:32:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/osnap" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Futures, meet Lucene]]></title>
            <link>https://medium.com/osnap/futures-meet-lucene-10a51b03a9fb?source=rss----e71cfaf8e398---4</link>
            <guid isPermaLink="false">https://medium.com/p/10a51b03a9fb</guid>
            <category><![CDATA[apache-lucene]]></category>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Josh Hight]]></dc:creator>
            <pubDate>Sat, 04 Feb 2017 01:16:36 GMT</pubDate>
            <atom:updated>2019-06-26T22:43:24.524Z</atom:updated>
            <content:encoded><![CDATA[<p>A while back I ran into a strange little problem, I needed to create a Lucene index with not only the contents of files but their hashes as well. It seemed like something that should be simple — and at first it was; I read through the file once with an InputStream to generate the hash, then wrapped a new InputStream in a Tika ParsingReader and passed it to Lucene so the file’s contents could be indexed.</p><p><a href="https://github.com/ThinAir/LuceneFutures/blob/master/src/DoubleRead.java">LuceneFutures/DoubleRead.java at master · ThinAir/LuceneFutures · GitHub</a></p><p>It worked and everything was lovely until I ran the benchmarks, then I was sad for a while. So I got to thinking, “We’re already reading through the file, and doing it exactly in sequence, with no seeking or fancy offset stuff; it seems like we should be able to squeeze a little more utility out of those expensive disk reads.” As it turns out, we can.</p><p><a href="https://github.com/ThinAir/LuceneFutures/blob/master/src/HashStream.java">LuceneFutures/HashStream.java at master · ThinAir/LuceneFutures · GitHub</a></p><p>What we do is wrap the input stream that we’re passing into the Tika ParsingReader in a filter class to do the hashing, this way, when Lucene reads the file in to do the indexing the hash will get generated as a side effect. Great! We’re all done, right? Well, not quite; we still have to include that hash as a Field in the indexed Document. The problem here is that the file is only read (and therefore hashed) when the Document is written to the index, at which point Fields can no longer be added except with some very expensive calls that effectively delete the document then re-write it back into the index. For obvious reasons I felt like this was too much work to do something relatively simple — so I went searching. I looked through the Lucene source and wrote things on whiteboards that confused my colleagues and upset small children, but at last I found what I was looking for; it turns out that when Lucene is indexing a Document, it reads Fields single threaded in the order in which they were added to the Document. The Lucene source necessary to demonstrate this is a little involved so it will not be included here, but if you’re curious some good places to start would be <a href="https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/document/Document.java">here</a>, <a href="https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java">here</a>, and <a href="https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/index/DefaultIndexingChain.java">here</a>.</p><p>This means that we can use the idea of a future to add a Field to Lucene, even though it doesn’t exist yet, because we know for a fact that in all cases it will exist by the time Lucene gets around to reading it. The way we do this is by subclassing Field and adding a little magic.</p><p><a href="https://github.com/ThinAir/LuceneFutures/blob/master/src/FutureTextField.java">LuceneFutures/FutureTextField.java at master · ThinAir/LuceneFutures · GitHub</a></p><p>You may be asking why we didn’t simply subclass TextField since we would desperately like to add this as a TextField (some of the more advanced Lucene programmers may instead be asking why we didn’t want to make this look more like a StringField. Hint: fingerprints). The problem with that is that TextField is written under the assumption that you are adding a Field that contains Text — not an unreasonable assumption but definitely an inconvenient one for our purposes. Having done this, we have only to implement a Future&lt;String&gt; for our HashStream to return and we should be off to the races.</p><p><a href="https://github.com/ThinAir/LuceneFutures/blob/master/src/HashStreamWithFuture.java">LuceneFutures/HashStreamWithFuture.java at master · ThinAir/LuceneFutures · GitHub</a></p><p>Observant readers will note that there is no sleeping, waiting, or locking of any kind in this Future. This could be considered a technically incomplete implementation of Future, while it may be that it is also free of all synchronization overhead and will always work correctly for this application.</p><p>All we have left to do now is write a (significantly simpler) main method.</p><p><a href="https://github.com/ThinAir/LuceneFutures/blob/master/src/SingleRead.java">LuceneFutures/SingleRead.java at master · ThinAir/LuceneFutures · GitHub</a></p><p>Now we run the benchmarks again — then jump for joy and go for a drink.</p><p><em>Josh Hight used to work at ThinAir Labs. He now works at DoorDash. You can find his latest open source project at </em><a href="http://github.com/joshbooks/JoshDB"><em>github.com/joshbooks/JoshDB</em></a><em>. He will happily respond to virtually any question posted in the comments. The source code for this piece can be found at </em><a href="https://github.com/ThinAir/LuceneFutures">https://github.com/ThinAir/LuceneFutures</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10a51b03a9fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/osnap/futures-meet-lucene-10a51b03a9fb">Futures, meet Lucene</a> was originally published in <a href="https://medium.com/osnap">osnap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[O(snap)]]></title>
            <link>https://medium.com/osnap/o-snap-e00d4468570b?source=rss----e71cfaf8e398---4</link>
            <guid isPermaLink="false">https://medium.com/p/e00d4468570b</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Cliff]]></dc:creator>
            <pubDate>Sat, 04 Feb 2017 01:00:40 GMT</pubDate>
            <atom:updated>2017-02-04T01:00:40.099Z</atom:updated>
            <content:encoded><![CDATA[<h4>Introducing The ThinAir Engineering Blog</h4><p>Many of you who know me personally know that I left the startup founder game a few months ago and took a new job at a startup called ThinAir. When deciding where I’d land, I had a lot of different choices in front of me, everything from joining a tech giant to slinging code at a tiny startup again. But instead I chose to join a growing startup as its first engineering manager.</p><p>What is ThinAir? Our mission is to secure the world’s data by treating our customer’s data as a Tier 1 asset and protecting it wherever it goes with strong encryption and exacting insight into how the data is being used. The big thing that attracted me to ThinAir was not just the scope of the market opportunity, but also the scope of the technical challenge.</p><p>Solving this enormous challenge spans desktop programming, distributed systems, machine learning, and cryptography. Not the least of which, of course, are the organizational issues that come along with building such an interdisciplinary team. So along the way we will learn a lot. We will encounter corner cases, hairy distributed systems bugs, performance optimizations, and surprising systems behavior at every turn.</p><p>In the spirit of what attracted me to ThinAir, it’s my pleasure to introduce the ThinAir engineering blog. Because when you’re blazing a new trail, it’s always nice to leave a few breadcrumbs behind.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e00d4468570b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/osnap/o-snap-e00d4468570b">O(snap)</a> was originally published in <a href="https://medium.com/osnap">osnap</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>