Skip to content

Commit

Permalink
Refactored client index (Velocidex#1214)
Browse files Browse the repository at this point in the history
On EFS the old client index was very non performant as EFS is very
slow and unable to handle large directories.

The new index has uses balanced b tree to keep directory size
small. We alos use a local in memory LRU to reduce number of EFS
operations.
  • Loading branch information
scudette authored Aug 24, 2021
1 parent 02a4afc commit aa2199b
Show file tree
Hide file tree
Showing 58 changed files with 1,344 additions and 695 deletions.
7 changes: 4 additions & 3 deletions api/notebooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,14 +1044,15 @@ func getAvailableTimelines(

result := []string{}
db, err := datastore.GetDB(config_obj)
files, err := db.ListChildren(
config_obj, path_manager.SuperTimelineDir(), 0, 1000)
files, err := db.ListChildren(config_obj, path_manager.SuperTimelineDir())
if err != nil {
return nil
}

for _, f := range files {
result = append(result, f.Base())
if !f.IsDir() {
result = append(result, f.Base())
}
}
return result
}
Expand Down
24 changes: 12 additions & 12 deletions api/proto/api.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 80 additions & 6 deletions api/proto/clients.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/proto/clients.proto
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,12 @@ message Uname {
"running on a 64 bit system)",
}];
};


message IndexRecord {
// Usually client id
string entity = 1;

// The term under which we indexed the entity.
string term = 2;
}
3 changes: 1 addition & 2 deletions api/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ func renderDBVFS(

// Figure out where the download info files are.
download_info_path := path_manager.VFSDownloadInfoPath(components)
downloaded_files, _ := db.ListChildren(
config_obj, download_info_path, 0, 1000)
downloaded_files, _ := db.ListChildren(config_obj, download_info_path)

result := &api_proto.VFSListResponse{}

Expand Down
12 changes: 6 additions & 6 deletions artifacts/definitions/Windows/Search/FileFinder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ sources:
LET file_search = SELECT FullPath,
get(item=Sys, field="mft") as Inode,
Mode.String AS Mode, Size,
Mtime AS Modified,
Mtime AS MTime,
Atime AS ATime,
Mtime AS MTime, "" AS Keywords,
Ctime AS CTime, IsDir
Btime AS BTime,
Ctime AS CTime, "" AS Keywords, IsDir
FROM glob(globs=SearchFilesGlobTable.Glob + SearchFilesGlob,
accessor=Accessor)
Expand Down Expand Up @@ -106,7 +106,7 @@ sources:
},
query={
SELECT FullPath, Inode, Mode,
Size, Modified, ATime, MTime, CTime,
Size, MTime, ATime, CTime, BTime,
str(str=String.Data) As Keywords, IsDir
FROM yara(files=FullPath,
Expand All @@ -116,8 +116,8 @@ sources:
})
}, else=modified_before)
SELECT FullPath, Inode, Mode, Size, Modified, ATime,
MTime, CTime, Keywords, IsDir,
SELECT FullPath, Inode, Mode, Size, MTime, ATime,
CTime, BTime, Keywords, IsDir,
if(condition=Upload_File and NOT IsDir,
then=upload(file=FullPath, accessor=Accessor)) AS Upload,
if(condition=Calculate_Hash and NOT IsDir,
Expand Down
2 changes: 1 addition & 1 deletion artifacts/definitions/Windows/Sys/Interfaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sources:
"Physical Address[^:]+: (?P<MAC>.+)\r\n",
"IPv4 Address[^:]+: (?P<IP>[0-9.]+)",
"Default Gateway[^:]+: (?P<Gateway>.+)\r\n",
"DNS Servers[^:]+: (?P<DNS>.+)\r\n",
"DNS Servers[^:]+: (?P<DNS>.+)\r\n [^ ]",
"DHCP Server[^:]+: (?P<DHCP>.+)\r\n"
]
) As Details FROM interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

C.4f5e52adf0a337a9all
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

C.4f5e52adf0a337a9desktop-6cbj8mj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

C.4f5e52adf0a337a9host:desktop-6cbj8mj
Empty file.
Empty file.
Empty file.
6 changes: 0 additions & 6 deletions artifacts/testdata/server/testcases/search.in.yaml

This file was deleted.

9 changes: 0 additions & 9 deletions artifacts/testdata/server/testcases/search.out.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (

var (
mu sync.Mutex

StopIteration = errors.New("StopIteration")
)

type SortingSense int
Expand All @@ -47,8 +49,8 @@ type DatastoreInfo struct {
Modified time.Time
}

// When WalkFunc return StopIteration we exit the walk.
type WalkFunc func(urn api.DSPathSpec) error
type ComponentWalkFunc func(components api.DSPathSpec) error

type DataStore interface {
// Retrieve all the client's tasks.
Expand Down Expand Up @@ -87,8 +89,7 @@ type DataStore interface {
// Lists all the children of a URN.
ListChildren(
config_obj *config_proto.Config,
urn api.DSPathSpec,
offset uint64, length uint64) ([]api.DSPathSpec, error)
urn api.DSPathSpec) ([]api.DSPathSpec, error)

Walk(config_obj *config_proto.Config,
root api.DSPathSpec, walkFn WalkFunc) error
Expand Down
Loading

0 comments on commit aa2199b

Please sign in to comment.