Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Programming Snapshot: Implementing Fast Queries for Local Files in Go

#1
Programming Snapshot: Implementing Fast Queries for Local Files in Go

To find files quickly in the deeply nested subdirectories of his home directory, Mike whips up a Go program to index file metadata in an SQLite database.

…the GitHub Codesearch [1] project, with its indexer built in Go, at least lets you browse locally available repositories, index them, and then search for code snippets in a flash. Its author, Russ Cox, then an intern at Google, explained later how the search works [2].

How about using a similar method to create an index of files below a start directory to perform quick queries such as: “Which files have recently been modified?” “Which are the biggest wasters of space?” Or “Which file names match the following pattern?”

Unix filesystems store metadata in inodes, which reside in flattened structures on disk that cause database-style queries to run at a snail’s pace. To take a look at a file’s metadata, run the statcommand on it and take a look at the file size and timestamps, such as the time of the last modification (Figure 2).

Figure 2: Inode metadata of a file, here determined by stat, can be used to build an index.

Newer filesystems like ZFS or Btrfs take a more database-like approach in the way they organize the files they contain but do not go far enough to be able to support meaningful queries from userspace.

Fast Forward Instead of Pause


For example, if you want to find all files over 100MB on the disk, you can do this with a find call like:

find / -type f -size +100M

If you are running the search on a traditional hard disk, take a coffee break. Even on a fast SSD, you need to prepare yourself for long search times in the minute range. The reason for this is that the data is scattered in a query-unfriendly way across the sectors of the disk.

Read more at Linux Pro Magazine

Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Recover your files from Btrfs snapshots xSicKxBot 0 1,625 10-05-2020, 04:17 PM
Last Post: xSicKxBot
  Fedora - Fedora 32: Simple Local File-Sharing with Samba xSicKxBot 0 1,719 06-13-2020, 02:44 AM
Last Post: xSicKxBot
  Fedora - Modifying Windows local accounts with Fedora and chntpw xSicKxBot 0 1,367 07-19-2019, 11:32 AM
Last Post: xSicKxBot
  Finding Files with mlocate xSicKxBot 0 1,650 03-18-2019, 07:05 PM
Last Post: xSicKxBot
  The State of the Octoverse: Top Programming Languages of 2018 xSicKxBot 0 1,799 11-21-2018, 04:56 PM
Last Post: xSicKxBot
  How to Search for Files from the Linux Command Line xSicKxBot 0 1,547 11-02-2018, 09:55 AM
Last Post: xSicKxBot
  Systemd Services: Monitoring Files and Directories xSicKxBot 0 1,969 06-19-2018, 02:29 PM
Last Post: xSicKxBot
  Using Linux as Local Server for Streaming Movies Using Kodi xSicKx 0 1,848 06-18-2018, 08:06 PM
Last Post: xSicKx
  Unrar all files from multiple subdirectories at once xSicKx 0 2,175 06-17-2018, 01:35 PM
Last Post: xSicKx
  [Ubuntu] How to extract .7z 7 zip files xSicKx 0 2,264 05-20-2018, 09:05 PM
Last Post: xSicKx

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016