Documentation
¶
Index ¶
- Constants
- func AccessNameToPrincipalName(accessPrincipalName string) (principalName string, isRole bool)
- func ConvertJSONNumbers(value interface{}) interface{}
- func ExpandingStar(set base.Set) base.Set
- func ForChangedUsers(a, b AccessMap, fn func(user string))
- func IgnoringStar(set base.Set) base.Set
- func IsValidChannel(channel string) bool
- func SetFromArray(names []string, mode StarMode) (base.Set, error)
- func SetOf(tb testing.TB, names ...string) base.Set
- type AccessMap
- type ActiveChannels
- func (ac *ActiveChannels) DecrChannel(channelName string)
- func (ac *ActiveChannels) DecrChannels(chans TimedSet)
- func (ac *ActiveChannels) IncrChannel(channelName string)
- func (ac *ActiveChannels) IncrChannels(chans TimedSet)
- func (ac *ActiveChannels) IsActive(channelName string) bool
- func (ac *ActiveChannels) UpdateChanged(changedChannels ChangedKeys)
- type ChangeLog
- func (cp *ChangeLog) Add(newEntry LogEntry)
- func (cp *ChangeLog) AddEntries(entries []*LogEntry)
- func (cp *ChangeLog) CopyRemovingEmptyEntries() *ChangeLog
- func (cp *ChangeLog) Dump()
- func (cp *ChangeLog) EntriesAfter(after uint64) []*LogEntry
- func (cp *ChangeLog) FilterAfter(after uint64)
- func (cp *ChangeLog) HasEmptyEntries() bool
- func (cp *ChangeLog) LastSequence() uint64
- func (c *ChangeLog) Len() int
- func (c *ChangeLog) Less(i, j int) bool
- func (c *ChangeLog) Sort()
- func (c *ChangeLog) Swap(i, j int)
- func (cp *ChangeLog) TruncateTo(maxLength int) int
- type ChangedKeys
- type ChannelMap
- type ChannelMapper
- type ChannelMapperOutput
- type ChannelRemoval
- type LogEntry
- type LogEntryType
- type StarMode
- type SyncRunner
- type TimedSet
- func (set TimedSet) Add(other TimedSet) bool
- func (set TimedSet) AddAtSequence(other TimedSet, atSequence uint64) bool
- func (set TimedSet) AddAtVbSequence(other TimedSet, atVbSequence VbSequence) bool
- func (set TimedSet) AddChannel(channelName string, atSequence uint64) bool
- func (set TimedSet) AllChannels() []string
- func (set TimedSet) AsSet() base.Set
- func (set TimedSet) CompareKeys(other TimedSet) ChangedKeys
- func (set TimedSet) Contains(ch string) bool
- func (set TimedSet) Copy() TimedSet
- func (set TimedSet) Equals(other base.Set) bool
- func (set TimedSet) MarshalJSON() ([]byte, error)
- func (set TimedSet) SequenceOnlySet() map[string]uint64
- func (set TimedSet) String() string
- func (setPtr *TimedSet) UnmarshalJSON(data []byte) error
- func (set TimedSet) UpdateAtSequence(other base.Set, sequence uint64) bool
- func (set TimedSet) UpdateIfPresent(other TimedSet)
- func (set TimedSet) Validate() error
- type VbSequence
Constants ¶
const ( LogEntryDocument = LogEntryType(iota) LogEntryPrincipal LogEntryCheckpoint LogEntryRollback LogEntryPurge )
const ( Deleted = 1 << iota // This rev is a deletion Removed // Doc was removed from this channel Hidden // This rev is not the default (hidden by a conflict) Conflict // Document is in conflict at this time Branched // Revision tree is branched Added // Doc was added to this channel )
Bits in LogEntry.Flags
const ( RemoveStar = StarMode(iota) KeepStar ExpandStar )
const AllChannelWildcard = "*" // wildcard for 'all channels'
const DocumentStarChannel = "!" // doc channel for "visible to all users"
const JavascriptMaxSafeInt = int64(1<<53 - 1)
Javscript max integer value (https://www.ecma-international.org/ecma-262/5.1/#sec-8.5)
const JavascriptMinSafeInt = -JavascriptMaxSafeInt
const RoleAccessPrefix = "role:"
Prefix used to identify roles in access grants
const UserStarChannel = "*" // user channel for "can access all docs"
Constants for the * channel variations
Variables ¶
This section is empty.
Functions ¶
func AccessNameToPrincipalName ¶
If the provided principal name (in access grant format) is a role, returns the role name without prefix
func ConvertJSONNumbers ¶
func ConvertJSONNumbers(value interface{}) interface{}
ConvertJSONNumbers converts json.Number values to javascript number objects for use in the sync function. Integers that would lose precision are left as json.Number, as are floats that can't be converted to float64.
func ExpandingStar ¶
If the set contains "*", returns a set of only "*". Else returns the original set.
func ForChangedUsers ¶
Calls the function for each user whose access is different between the two AccessMaps
func IgnoringStar ¶
Returns a set with any "*" channel removed.
func IsValidChannel ¶
func SetFromArray ¶
Creates a new Set from an array of strings. Returns an error if any names are invalid.
Types ¶
type AccessMap ¶
Maps user names (or role names prefixed with "role:") to arrays of channel or role names
type ActiveChannels ¶
type ActiveChannels struct {
// contains filtered or unexported fields
}
activeChannels is a concurrency-safe map of active replications per channel, modified via incr/decr operations. Incrementing a channel not already in the map adds it to the map. Decrementing a channel's active count to zero removes its entry from the map.
Note: private properties shouldn't be accessed directly, to support potential refactoring of activeChannels to use a sharded map as needed.
func NewActiveChannels ¶
func NewActiveChannels(activeChannelCountStat *expvar.Int) *ActiveChannels
func (*ActiveChannels) DecrChannel ¶
func (ac *ActiveChannels) DecrChannel(channelName string)
func (*ActiveChannels) DecrChannels ¶
func (ac *ActiveChannels) DecrChannels(chans TimedSet)
func (*ActiveChannels) IncrChannel ¶
func (ac *ActiveChannels) IncrChannel(channelName string)
func (*ActiveChannels) IncrChannels ¶
func (ac *ActiveChannels) IncrChannels(chans TimedSet)
Active channel counts track channels being replicated by an active changes request.
func (*ActiveChannels) IsActive ¶
func (ac *ActiveChannels) IsActive(channelName string) bool
func (*ActiveChannels) UpdateChanged ¶
func (ac *ActiveChannels) UpdateChanged(changedChannels ChangedKeys)
Update changed increments/decrements active channel counts based on a set of changed channels. Triggered when the set of channels being replicated by a given replication changes.
type ChangeLog ¶
type ChangeLog struct {
Since uint64 // Sequence this log is valid _after_, i.e. max sequence not in the log
Entries []*LogEntry // Ordered entries
}
A sequential log of document revisions added to a channel, used to generate _changes feeds. The log is sorted by increasing sequence number.
func (*ChangeLog) AddEntries ¶
func (*ChangeLog) CopyRemovingEmptyEntries ¶
Returns a copy without empty (no DocID) entries that resulted from revisions that have been replaced. Result does not share a slice with the original cp.
func (*ChangeLog) EntriesAfter ¶
Returns a slice of all entries added after the one with sequence number 'after'. (They're not guaranteed to have higher sequence numbers; sequences may be added out of order.)
func (*ChangeLog) FilterAfter ¶
Filters the log to only the entries added after the one with sequence number 'after.
func (*ChangeLog) HasEmptyEntries ¶
func (*ChangeLog) LastSequence ¶
func (*ChangeLog) TruncateTo ¶
Removes the oldest entries to limit the log's length to `maxLength`.
type ChangedKeys ¶
TimedSetDiff stores the result of TimedSet.CompareKeys Elements present in the set but not in the other are returned with value true Elements present in the other set but not in set are returned with value false Unchanged elements are not included in ChangedKeys
type ChannelMap ¶
type ChannelMap map[string]*ChannelRemoval
func (ChannelMap) ChannelsRemovedAtSequence ¶
func (channelMap ChannelMap) ChannelsRemovedAtSequence(seq uint64) (ChannelMap, string)
func (ChannelMap) KeySet ¶
func (channelMap ChannelMap) KeySet() []string
type ChannelMapper ¶
type ChannelMapper struct {
*sgbucket.JSServer // "Superclass"
}
func NewChannelMapper ¶
func NewChannelMapper(fnSource string) *ChannelMapper
func NewDefaultChannelMapper ¶
func NewDefaultChannelMapper() *ChannelMapper
func (*ChannelMapper) MapToChannelsAndAccess ¶
func (mapper *ChannelMapper) MapToChannelsAndAccess(body map[string]interface{}, oldBodyJSON string, userCtx map[string]interface{}) (*ChannelMapperOutput, error)
type ChannelMapperOutput ¶
type ChannelMapperOutput struct {
Channels base.Set // channels assigned to the document via channel() callback
Roles AccessMap // roles granted to users via role() callback
Access AccessMap // channels granted to users via access() callback
Rejection error // Error associated with failed validate (require callbacks, etc)
Expiry *uint32 // Expiry value specified by expiry() callback. Standard CBS expiry format: seconds if less than 30 days, epoch time otherwise
}
* Result of running a channel-mapper function.
type ChannelRemoval ¶
type LogEntry ¶
type LogEntry struct {
Sequence uint64 // Sequence number
DocID string // Document ID
RevID string // Revision ID
Flags uint8 // Deleted/Removed/Hidden flags
VbNo uint16 // vbucket number
TimeSaved time.Time // Time doc revision was saved (just used for perf metrics)
TimeReceived time.Time // Time received from tap feed
Channels ChannelMap // Channels this entry is in or was removed from
Skipped bool // Late arriving entry
Type LogEntryType // Log entry type
Value []byte // Snapshot metadata (when Type=LogEntryCheckpoint)
PrevSequence uint64 // Sequence of previous active revision
IsPrincipal bool // Whether the log-entry is a tracking entry for a principal doc
}
type SyncRunner ¶
type SyncRunner struct {
sgbucket.JSRunner // "Superclass"
// contains filtered or unexported fields
}
An object that runs a specific JS sync() function. Not thread-safe!
func NewSyncRunner ¶
func NewSyncRunner(funcSource string) (*SyncRunner, error)
func (*SyncRunner) MapToChannelsAndAccess ¶
func (runner *SyncRunner) MapToChannelsAndAccess(body map[string]interface{}, oldBodyJSON string, userCtx map[string]interface{}) (*ChannelMapperOutput, error)
func (*SyncRunner) SetFunction ¶
func (runner *SyncRunner) SetFunction(funcSource string) (bool, error)
type TimedSet ¶
type TimedSet map[string]VbSequence
A mutable mapping from channel names to sequence numbers (interpreted as the sequence when the channel was added.)
func AtSequence ¶
Creates a new TimedSet from a Set plus a sequence
func TimedSetFromString ¶
Parses a string as generated from TimedSet.String(). Returns nil on failure. An empty string successfully parses to an empty TimedSet.
func (TimedSet) Add ¶
Merges the other set into the receiver. In case of collisions the earliest sequence wins.
func (TimedSet) AddAtSequence ¶
Merges the other set into the receiver at a given sequence. */
func (TimedSet) AddAtVbSequence ¶
func (set TimedSet) AddAtVbSequence(other TimedSet, atVbSequence VbSequence) bool
Merges the other set into the receiver at a given sequence. */
func (TimedSet) AddChannel ¶
func (TimedSet) AllChannels ¶
func (TimedSet) CompareKeys ¶
func (set TimedSet) CompareKeys(other TimedSet) ChangedKeys
CompareKeys returns sets of added and removed keys between two sets. Elements present in the set but not in the other are returned as 'added'. Elements present in the other set but not in set are returned as 'removed'. of false.
func (TimedSet) MarshalJSON ¶
func (TimedSet) SequenceOnlySet ¶
func (TimedSet) String ¶
Encodes a TimedSet as a string (as sent in the public _changes feed.) This string can later be turned back into a TimedSet by calling TimedSetFromString().
func (*TimedSet) UnmarshalJSON ¶
TimedSet can unmarshal from either:
- The regular format {"channel":vbSequence, ...}
- The sequence-only format {"channel":uint64, ...} or
- An array of channel names.
In the last two cases, all vbNos will be 0. In the latter case all the sequences will be 0.
func (TimedSet) UpdateAtSequence ¶
Updates membership to match the given Set. Newly added members will have the given sequence.
func (TimedSet) UpdateIfPresent ¶
For any channel present in both the set and the other set, updates the sequence to the value from the other set
type VbSequence ¶
Vb and Sequence struct that's compatible with sequence-only (global sequence) mode
func NewVbSequence ¶
func NewVbSequence(vbNo uint16, sequence uint64) VbSequence
func NewVbSimpleSequence ¶
func NewVbSimpleSequence(sequence uint64) VbSequence
func (VbSequence) Copy ¶
func (vbs VbSequence) Copy() VbSequence
func (VbSequence) Equals ¶
func (vbs VbSequence) Equals(other VbSequence) bool
func (VbSequence) String ¶
func (vbs VbSequence) String() string