mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
This commit adds `TranslationSources` to the cluster `ResizeInstruction`. These are the sources of translation partitions which the receiving node needs in order to support partition distribution in the new, resized cluster. This also fixes a bug where index options were not being encode in the proto Index object. That meant that the schema transferred via protobuf was not correct. The reason why things normally worked is because index creation typically happens on the CreateIndex message, which does include the options. TODO: - [ ] implement the TranslateStore interface for `InMemTranslateStore` and `mock.TranslateStore` - [ ] surely need some more tests around the `ReadFrom` and `WriteTo`
107 lines
2.8 KiB
Go
107 lines
2.8 KiB
Go
// Copyright 2017 Pilosa Corp.
|
|
//
|
|
// 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.
|
|
|
|
package mock
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/pilosa/pilosa/v2"
|
|
)
|
|
|
|
var _ pilosa.TranslateStore = (*TranslateStore)(nil)
|
|
|
|
type TranslateStore struct {
|
|
CloseFunc func() error
|
|
MaxIDFunc func() (uint64, error)
|
|
PartitionIDFunc func() int
|
|
ReadOnlyFunc func() bool
|
|
SetReadOnlyFunc func(v bool)
|
|
TranslateKeyFunc func(key string) (uint64, error)
|
|
TranslateKeysFunc func(keys []string) ([]uint64, error)
|
|
TranslateIDFunc func(id uint64) (string, error)
|
|
TranslateIDsFunc func(ids []uint64) ([]string, error)
|
|
ForceSetFunc func(id uint64, key string) error
|
|
EntryReaderFunc func(ctx context.Context, offset uint64) (pilosa.TranslateEntryReader, error)
|
|
}
|
|
|
|
func (s *TranslateStore) Close() error {
|
|
return s.CloseFunc()
|
|
}
|
|
|
|
func (s *TranslateStore) MaxID() (uint64, error) {
|
|
return s.MaxIDFunc()
|
|
}
|
|
|
|
func (s *TranslateStore) PartitionID() int {
|
|
return s.PartitionIDFunc()
|
|
}
|
|
|
|
func (s *TranslateStore) ReadOnly() bool {
|
|
return s.ReadOnlyFunc()
|
|
}
|
|
|
|
func (s *TranslateStore) SetReadOnly(v bool) {
|
|
s.SetReadOnlyFunc(v)
|
|
}
|
|
|
|
func (s *TranslateStore) TranslateKey(key string) (uint64, error) {
|
|
return s.TranslateKeyFunc(key)
|
|
}
|
|
|
|
func (s *TranslateStore) TranslateKeys(keys []string) ([]uint64, error) {
|
|
return s.TranslateKeysFunc(keys)
|
|
}
|
|
|
|
func (s *TranslateStore) TranslateID(id uint64) (string, error) {
|
|
return s.TranslateIDFunc(id)
|
|
}
|
|
|
|
func (s *TranslateStore) TranslateIDs(ids []uint64) ([]string, error) {
|
|
return s.TranslateIDsFunc(ids)
|
|
}
|
|
|
|
func (s *TranslateStore) ForceSet(id uint64, key string) error {
|
|
return s.ForceSetFunc(id, key)
|
|
}
|
|
|
|
func (s *TranslateStore) EntryReader(ctx context.Context, offset uint64) (pilosa.TranslateEntryReader, error) {
|
|
return s.EntryReaderFunc(ctx, offset)
|
|
}
|
|
|
|
// TODO: implement this
|
|
func (s *TranslateStore) WriteTo(w io.Writer) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
// TODO: implement this
|
|
func (s *TranslateStore) ReadFrom(r io.Reader) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
var _ pilosa.TranslateEntryReader = (*TranslateEntryReader)(nil)
|
|
|
|
type TranslateEntryReader struct {
|
|
CloseFunc func() error
|
|
ReadEntryFunc func(entry *pilosa.TranslateEntry) error
|
|
}
|
|
|
|
func (r *TranslateEntryReader) Close() error {
|
|
return r.CloseFunc()
|
|
}
|
|
|
|
func (r *TranslateEntryReader) ReadEntry(entry *pilosa.TranslateEntry) error {
|
|
return r.ReadEntryFunc(entry)
|
|
}
|