forked from cs3org/reva
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata storage and indexer (cs3org#2585)
* Move Indexer and Sync over from ocis-pkg * Simplify and DRY up the indexer package * Port the metadata storage layer over from ocis-pkg * Adapt go modules * Refactor, make tests pass * Try to make authenticated requests using machine auth Spoiler: It doesn't work * Allow indexing by nested fields * Do not hardcode the metadata storage space id * Fix authenticating metadata storage requests * Use correct space root when the space already exists * Allow for indexing using an index function That can be used in cases where it's not a single field holding the information, e.g. in case of polymorphism. * Add changelog * Make hound happy * Adapt license header text * Add missing license headers * Do not try to load the cs3 share manager yet * Remove unused cache code * Fix tests * Apply review suggestions * Optimize dedup() according to review suggestion * Fix missing license headers * CI is slow..
- Loading branch information
Showing
30 changed files
with
3,347 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Enhancement: Add metadata storage layer and indexer | ||
|
||
We ported over and enhanced the metadata storage layer and indexer from ocis-pkg so that it can be used by reva services as well. | ||
|
||
https://github.com/cs3org/reva/pull/2585 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2018-2022 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package errors | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cs3org/reva/pkg/storage/utils/indexer/option" | ||
) | ||
|
||
// AlreadyExistsErr implements the Error interface. | ||
type AlreadyExistsErr struct { | ||
TypeName, Value string | ||
IndexBy option.IndexBy | ||
} | ||
|
||
func (e *AlreadyExistsErr) Error() string { | ||
return fmt.Sprintf("%s with %s=%s does already exist", e.TypeName, e.IndexBy.String(), e.Value) | ||
} | ||
|
||
// IsAlreadyExistsErr checks whether an error is of type AlreadyExistsErr. | ||
func IsAlreadyExistsErr(e error) bool { | ||
_, ok := e.(*AlreadyExistsErr) | ||
return ok | ||
} | ||
|
||
// NotFoundErr implements the Error interface. | ||
type NotFoundErr struct { | ||
TypeName, Value string | ||
IndexBy option.IndexBy | ||
} | ||
|
||
func (e *NotFoundErr) Error() string { | ||
return fmt.Sprintf("%s with %s=%s not found", e.TypeName, e.IndexBy.String(), e.Value) | ||
} | ||
|
||
// IsNotFoundErr checks whether an error is of type IsNotFoundErr. | ||
func IsNotFoundErr(e error) bool { | ||
_, ok := e.(*NotFoundErr) | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2018-2022 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package indexer | ||
|
||
// dedup removes duplicate values in given slice | ||
func dedup(s []string) []string { | ||
var out []string | ||
exists := make(map[string]bool) | ||
for _, ss := range s { | ||
if _, ok := exists[ss]; !ok { | ||
out = append(out, ss) | ||
exists[ss] = true | ||
} | ||
} | ||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2018-2022 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package indexer | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/onsi/gomega/gmeasure" | ||
) | ||
|
||
var _ = Describe("Helper", func() { | ||
Describe("dedup", func() { | ||
It("dedups reasonably fast", func() { | ||
experiment := gmeasure.NewExperiment("deduplicating string slices") | ||
AddReportEntry(experiment.Name, experiment) | ||
|
||
experiment.Sample(func(idx int) { | ||
slice := []string{} | ||
for i := 0; i < 900; i++ { | ||
slice = append(slice, strconv.Itoa(i)) | ||
} | ||
for i := 0; i < 100; i++ { | ||
slice = append(slice, strconv.Itoa(i)) | ||
} | ||
experiment.MeasureDuration("repagination", func() { | ||
dedupped := dedup(slice) | ||
Expect(len(dedupped)).To(Equal(900)) | ||
}) | ||
}, gmeasure.SamplingConfig{N: 100000, Duration: 10 * time.Second}) | ||
|
||
repaginationStats := experiment.GetStats("repagination") | ||
medianDuration := repaginationStats.DurationFor(gmeasure.StatMedian) | ||
Expect(medianDuration).To(BeNumerically("<", 1200*time.Microsecond)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.