channels

package
v0.0.0-...-1b51d53 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogEntryDocument = LogEntryType(iota)
	LogEntryPrincipal
	LogEntryCheckpoint
	LogEntryRollback
)
View Source
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

View Source
const (
	RemoveStar = StarMode(iota)
	KeepStar
	ExpandStar
)
View Source
const AllChannelWildcard = "*" // wildcard for 'all channels'
View Source
const DocumentStarChannel = "!" // doc channel for "visible to all users"
View Source
const UserStarChannel = "*" // user channel for "can access all docs"

Constants for the * channel variations

Variables

This section is empty.

Functions

func ExpandingStar

func ExpandingStar(set base.Set) base.Set

If the set contains "*", returns a set of only "*". Else returns the original set.

func ForChangedUsers

func ForChangedUsers(a, b AccessMap, fn func(user string))

Calls the function for each user whose access is different between the two AccessMaps

func IgnoringStar

func IgnoringStar(set base.Set) base.Set

Returns a set with any "*" channel removed.

func IsValidChannel

func IsValidChannel(channel string) bool

func SetFromArray

func SetFromArray(names []string, mode StarMode) (base.Set, error)

Creates a new Set from an array of strings. Returns an error if any names are invalid.

func SetOf

func SetOf(names ...string) base.Set

Creates a set from zero or more inline string arguments. Channel names must be valid, else the function will panic, so this should only be called with hardcoded known-valid strings.

func ValidateChannelSet

func ValidateChannelSet(set base.Set) error

Types

type AccessMap

type AccessMap map[string]base.Set

Maps user names (or role names prefixed with "role:") to arrays of channel or role names

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) Add

func (cp *ChangeLog) Add(newEntry LogEntry)

Adds a new entry, always at the end of the log.

func (*ChangeLog) AddEntries

func (cp *ChangeLog) AddEntries(entries []*LogEntry)

func (*ChangeLog) CopyRemovingEmptyEntries

func (cp *ChangeLog) CopyRemovingEmptyEntries() *ChangeLog

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) Dump

func (cp *ChangeLog) Dump()

func (*ChangeLog) EntriesAfter

func (cp *ChangeLog) EntriesAfter(after uint64) []*LogEntry

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

func (cp *ChangeLog) FilterAfter(after uint64)

Filters the log to only the entries added after the one with sequence number 'after.

func (*ChangeLog) HasEmptyEntries

func (cp *ChangeLog) HasEmptyEntries() bool

func (*ChangeLog) LastSequence

func (cp *ChangeLog) LastSequence() uint64

func (*ChangeLog) Len

func (c *ChangeLog) Len() int

func (*ChangeLog) Less

func (c *ChangeLog) Less(i, j int) bool

func (*ChangeLog) Sort

func (c *ChangeLog) Sort()

Sorts the entries by increasing sequence.

func (*ChangeLog) Swap

func (c *ChangeLog) Swap(i, j int)

func (*ChangeLog) TruncateTo

func (cp *ChangeLog) TruncateTo(maxLength int) int

Removes the oldest entries to limit the log's length to `maxLength`.

type ChannelMap

type ChannelMap map[string]*ChannelRemoval

func (ChannelMap) ChannelsRemovedAtSequence

func (channelMap ChannelMap) ChannelsRemovedAtSequence(seq uint64) (ChannelMap, 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
	Roles     AccessMap // roles granted to users via role() callback
	Access    AccessMap
	Rejection error
}

* Result of running a channel-mapper function.

type ChannelRemoval

type ChannelRemoval struct {
	Seq     uint64 `json:"seq,omitempty"`
	RevID   string `json:"rev"`
	Deleted bool   `json:"del,omitempty"`
}

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
}

type LogEntryType

type LogEntryType uint8

LogEntryType

type StarMode

type StarMode int

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

func AtSequence(set base.Set, sequence uint64) TimedSet

Creates a new TimedSet from a Set plus a sequence

func TimedSetFromSequenceOnlySet

func TimedSetFromSequenceOnlySet(sequenceOnlySet map[string]uint64) TimedSet

func TimedSetFromString

func TimedSetFromString(encoded string) TimedSet

Parses a string as generated from TimedSet.String(). Returns nil on failure. An empty string successfully parses to an empty TimedSet.

func (TimedSet) Add

func (set TimedSet) Add(other TimedSet) bool

Merges the other set into the receiver. In case of collisions the earliest sequence wins.

func (TimedSet) AddAtSequence

func (set TimedSet) AddAtSequence(other TimedSet, atSequence uint64) bool

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 (set TimedSet) AddChannel(channelName string, atSequence uint64) bool

func (TimedSet) AllChannels

func (set TimedSet) AllChannels() []string

func (TimedSet) AsSet

func (set TimedSet) AsSet() base.Set

Converts a TimedSet to a Set

func (TimedSet) Contains

func (set TimedSet) Contains(ch string) bool

Returns true if the set includes the channel.

func (TimedSet) Copy

func (set TimedSet) Copy() TimedSet

func (TimedSet) Equals

func (set TimedSet) Equals(other base.Set) bool

Check for matching entry names, ignoring sequence

func (TimedSet) MarshalJSON

func (set TimedSet) MarshalJSON() ([]byte, error)

func (TimedSet) SequenceOnlySet

func (set TimedSet) SequenceOnlySet() map[string]uint64

func (TimedSet) String

func (set TimedSet) String() 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

func (setPtr *TimedSet) UnmarshalJSON(data []byte) error

TimedSet can unmarshal from either:

  1. The regular format {"channel":vbSequence, ...}
  2. The sequence-only format {"channel":uint64, ...} or
  3. 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

func (set TimedSet) UpdateAtSequence(other base.Set, sequence uint64) bool

Updates membership to match the given Set. Newly added members will have the given sequence.

func (TimedSet) UpdateIfPresent

func (set TimedSet) UpdateIfPresent(other TimedSet)

For any channel present in both the set and the other set, updates the sequence to the value from the other set

func (TimedSet) Validate

func (set TimedSet) Validate() error

type VbSequence

type VbSequence struct {
	VbNo     *uint16 `json:"vb,omitempty"`
	Sequence uint64  `json:"seq"`
}

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) AsVbSeq

func (vbs VbSequence) AsVbSeq() base.VbSeq

func (VbSequence) CompareTo

func (v VbSequence) CompareTo(other VbSequence) base.CompareResult

Compares to other VbSequence. If EITHER vbNo is nil, does a sequence-only comparison

func (VbSequence) Copy

func (vbs VbSequence) Copy() VbSequence

func (VbSequence) Equals

func (vbs VbSequence) Equals(other VbSequence) bool

func (VbSequence) IsLTEClock

func (v VbSequence) IsLTEClock(clock base.SequenceClock) bool

Is sequence less than or equal to corresponding clock entry

func (VbSequence) String

func (vbs VbSequence) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL