本文整理汇总了Golang中github.com/couchbaselabs/sync_gateway/base.Warn函数的典型用法代码示例。如果您正苦于以下问题:Golang Warn函数的具体用法?Golang Warn怎么用?Golang Warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PushRevision
// Saves a new local revision to the external bucket.
func (s *Shadower) PushRevision(doc *document) {
defer func() { atomic.AddUint64(&s.pushCount, 1) }()
if !s.docIDMatches(doc.ID) {
return
} else if doc.newestRevID() == doc.UpstreamRev {
return // This revision was pulled from the external bucket, so don't push it back!
}
var err error
if doc.Flags&channels.Deleted != 0 {
base.LogTo("Shadow", "Pushing %q, rev %q [deletion]", doc.ID, doc.CurrentRev)
err = s.bucket.Delete(doc.ID)
} else {
base.LogTo("Shadow", "Pushing %q, rev %q", doc.ID, doc.CurrentRev)
body := doc.getRevision(doc.CurrentRev)
if body == nil {
base.Warn("Can't get rev %q.%q to push to external bucket", doc.ID, doc.CurrentRev)
return
}
err = s.bucket.Set(doc.ID, 0, body)
}
if err != nil {
base.Warn("Error pushing rev of %q to external bucket: %v", doc.ID, err)
}
}
示例2: writeJSONStatus
// Writes an object to the response in JSON format.
// If status is nonzero, the header will be written with that status.
func (h *handler) writeJSONStatus(status int, value interface{}) {
if !h.requestAccepts("application/json") {
base.Warn("Client won't accept JSON, only %s", h.rq.Header.Get("Accept"))
h.writeStatus(http.StatusNotAcceptable, "only application/json available")
return
}
jsonOut, err := json.Marshal(value)
if err != nil {
base.Warn("Couldn't serialize JSON for %v", value)
h.writeStatus(http.StatusInternalServerError, "JSON serialization failed")
return
}
if PrettyPrint {
var buffer bytes.Buffer
json.Indent(&buffer, jsonOut, "", " ")
jsonOut = append(buffer.Bytes(), '\n')
}
h.setHeader("Content-Type", "application/json")
if h.rq.Method != "HEAD" {
h.setHeader("Content-Length", fmt.Sprintf("%d", len(jsonOut)))
if status > 0 {
h.response.WriteHeader(status)
h.logStatus(status, "")
}
h.response.Write(jsonOut)
} else if status > 0 {
h.response.WriteHeader(status)
h.logStatus(status, "")
}
}
示例3: addDocToChangeEntry
// Adds a document body and/or its conflicts to a ChangeEntry
func (db *Database) addDocToChangeEntry(entry *ChangeEntry, options ChangesOptions) {
includeConflicts := options.Conflicts && entry.branched
if !options.IncludeDocs && !includeConflicts {
return
}
doc, err := db.GetDoc(entry.ID)
if err != nil {
base.Warn("Changes feed: error getting doc %q: %v", entry.ID, err)
return
}
revID := entry.Changes[0]["rev"]
if includeConflicts {
doc.History.forEachLeaf(func(leaf *RevInfo) {
if leaf.ID != revID {
entry.Changes = append(entry.Changes, ChangeRev{"rev": leaf.ID})
if !leaf.Deleted {
entry.Deleted = false
}
}
})
}
if options.IncludeDocs {
var err error
entry.Doc, err = db.getRevFromDoc(doc, revID, false)
if err != nil {
base.Warn("Changes feed: error getting doc %q/%q: %v", doc.ID, revID, err)
}
}
}
示例4: TruncateEncodedChangeLog
// Removes the oldest entries to limit the log's length to `maxLength`.
// This is the same as ChangeLog.Truncate except it works directly on the encoded form, which is
// much faster than decoding+truncating+encoding.
func TruncateEncodedChangeLog(r *bytes.Reader, maxLength, minLength int, w io.Writer) (removed int, newLength int) {
since := readSequence(r)
// Find the starting position and sequence of each entry:
entryPos := make([]int64, 0, 1000)
entrySeq := make([]uint64, 0, 1000)
for {
pos, err := r.Seek(0, 1)
if err != nil {
panic("Seek??")
}
flags, err := r.ReadByte()
if err != nil {
if err == io.EOF {
break // eof
}
panic("ReadByte failed")
}
seq := readSequence(r)
skipString(r)
skipString(r)
skipString(r)
if flags > kMaxFlag {
panic(fmt.Sprintf("TruncateEncodedChangeLog: bad flags 0x%x, entry %d, offset %d",
flags, len(entryPos), pos))
}
entryPos = append(entryPos, pos)
entrySeq = append(entrySeq, seq)
}
// How many entries to remove?
// * Leave no more than maxLength entries
// * Every sequence value removed should be less than every sequence remaining.
// * The new 'since' value should be the maximum sequence removed.
oldLength := len(entryPos)
removed = oldLength - maxLength
if removed <= 0 {
removed = 0
} else {
pivot, newSince := findPivot(entrySeq, removed-1)
removed = pivot + 1
if oldLength-removed >= minLength {
since = newSince
} else {
removed = 0
base.Warn("TruncateEncodedChangeLog: Couldn't find a safe place to truncate")
//TODO: Possibly find a pivot earlier than desired?
}
}
// Write the updated Since and the remaining entries:
writeSequence(since, w)
if _, err := r.Seek(entryPos[removed], 0); err != nil {
panic("Seek back???")
}
if _, err := io.Copy(w, r); err != nil {
panic("Copy???")
}
return removed, oldLength - removed
}
示例5: ForEachDocID
// Iterates over all documents in the database, calling the callback function on each
func (db *Database) ForEachDocID(callback ForEachDocIDFunc) error {
type viewRow struct {
Key string
Value struct {
RevID string `json:"r"`
Sequence uint64 `json:"s"`
Channels []string `json:"c"`
}
}
var vres struct {
Rows []viewRow
}
opts := Body{"stale": false, "reduce": false}
err := db.Bucket.ViewCustom("sync_housekeeping", "all_docs", opts, &vres)
if err != nil {
base.Warn("all_docs got error: %v", err)
return err
}
for _, row := range vres.Rows {
err = callback(IDAndRev{row.Key, row.Value.RevID, row.Value.Sequence}, row.Value.Channels)
if err != nil {
return err
}
}
return nil
}
示例6: backupAncestorRevs
// Moves a revision's ancestor's body out of the document object and into a separate db doc.
func (db *Database) backupAncestorRevs(doc *document, revid string) error {
// Find an ancestor that still has JSON in the document:
var json []byte
for {
if revid = doc.History.getParent(revid); revid == "" {
return nil // No ancestors with JSON found
} else if json = doc.getRevisionJSON(revid); json != nil {
break
}
}
// Store the JSON as a separate doc in the bucket:
if err := db.setOldRevisionJSON(doc.ID, revid, json); err != nil {
// This isn't fatal since we haven't lost any information; just warn about it.
base.Warn("backupAncestorRevs failed: doc=%q rev=%q err=%v", doc.ID, revid, err)
return err
}
// Nil out the rev's body in the document struct:
if revid == doc.CurrentRev {
doc.body = nil
} else {
doc.History.setRevisionBody(revid, nil)
}
base.LogTo("CRUD+", "Backed up obsolete rev %q/%q", doc.ID, revid)
return nil
}
示例7: ReadJSONFromMIME
// Parses a JSON MIME body, unmarshaling it into "into".
func ReadJSONFromMIME(headers http.Header, input io.Reader, into interface{}) error {
contentType := headers.Get("Content-Type")
if contentType != "" && !strings.HasPrefix(contentType, "application/json") {
return base.HTTPErrorf(http.StatusUnsupportedMediaType, "Invalid content type %s", contentType)
}
switch headers.Get("Content-Encoding") {
case "gzip":
var err error
if input, err = gzip.NewReader(input); err != nil {
return err
}
case "":
break
default:
return base.HTTPErrorf(http.StatusUnsupportedMediaType, "Unsupported Content-Encoding; use gzip")
}
decoder := json.NewDecoder(input)
if err := decoder.Decode(into); err != nil {
base.Warn("Couldn't parse JSON in HTTP request: %v", err)
return base.HTTPErrorf(http.StatusBadRequest, "Bad JSON")
}
return nil
}
示例8: readTapFeed
// Main loop that pulls changes from the external bucket. (Runs in its own goroutine.)
func (s *Shadower) readTapFeed() {
vbucketsFilling := 0
for event := range s.tapFeed.Events() {
switch event.Opcode {
case walrus.TapBeginBackfill:
if vbucketsFilling == 0 {
base.LogTo("Shadow", "Reading history of external bucket")
}
vbucketsFilling++
//base.LogTo("Shadow", "Reading history of external bucket")
case walrus.TapMutation, walrus.TapDeletion:
key := string(event.Key)
// Ignore ephemeral documents or ones whose ID would conflict with our metadata
if event.Expiry > 0 || !s.docIDMatches(key) {
break
}
isDeletion := event.Opcode == walrus.TapDeletion
err := s.pullDocument(key, event.Value, isDeletion, event.Sequence, event.Flags)
if err != nil {
base.Warn("Error applying change from external bucket: %v", err)
}
case walrus.TapEndBackfill:
if vbucketsFilling--; vbucketsFilling == 0 {
base.LogTo("Shadow", "Caught up with history of external bucket")
}
}
}
base.LogTo("Shadow", "End of tap feed(?)")
}
示例9: lastSequence
func (s *sequenceAllocator) lastSequence() (uint64, error) {
last, err := s.bucket.Incr("_sync:seq", 0, 0, 0)
if err != nil {
base.Warn("Error from Incr in lastSequence(): %v", err)
}
return last, err
}
示例10: readTapFeed
// Main loop that pulls changes from the external bucket. (Runs in its own goroutine.)
func (s *Shadower) readTapFeed() {
vbucketsFilling := 0
for event := range s.tapFeed.Events() {
switch event.Opcode {
case walrus.TapBeginBackfill:
if vbucketsFilling == 0 {
base.LogTo("Shadow", "Reading history of external bucket")
}
vbucketsFilling++
//base.LogTo("Shadow", "Reading history of external bucket")
case walrus.TapMutation, walrus.TapDeletion:
key := string(event.Key)
if !s.docIDMatches(key) {
break
}
isDeletion := event.Opcode == walrus.TapDeletion
if !isDeletion && event.Expiry > 0 {
break // ignore ephemeral documents
}
err := s.pullDocument(key, event.Value, isDeletion, event.Sequence, event.Flags)
if err != nil {
base.Warn("Error applying change from external bucket: %v", err)
}
atomic.AddUint64(&s.pullCount, 1)
case walrus.TapEndBackfill:
if vbucketsFilling--; vbucketsFilling == 0 {
base.LogTo("Shadow", "Caught up with history of external bucket")
}
}
}
base.LogTo("Shadow", "End of tap feed(?)")
}
示例11: processPrincipalDoc
func (c *changeCache) processPrincipalDoc(docID string, docJSON []byte, isUser bool) {
// Currently the cache isn't really doing much with user docs; mostly it needs to know about
// them because they have sequence numbers, so without them the sequence of sequences would
// have gaps in it, causing later sequences to get stuck in the queue.
princ, err := c.context.Authenticator().UnmarshalPrincipal(docJSON, "", 0, isUser)
if princ == nil {
base.Warn("changeCache: Error unmarshaling doc %q: %v", docID, err)
return
}
sequence := princ.Sequence()
if sequence <= c.initialSequence {
return // Tap is sending us an old value from before I started up; ignore it
}
// Now add the (somewhat fictitious) entry:
change := &LogEntry{
Sequence: sequence,
TimeReceived: time.Now(),
}
if isUser {
change.DocID = "_user/" + princ.Name()
} else {
change.DocID = "_role/" + princ.Name()
}
base.LogTo("Cache", "Received #%d (%q)", change.Sequence, change.DocID)
c.processEntry(change)
}
示例12: handlePersonaPOST
// POST /_persona creates a browserID-based login session and sets its cookie.
// It's API-compatible with the CouchDB plugin: <https://github.com/iriscouch/browserid_couchdb/>
func (h *handler) handlePersonaPOST() error {
var params struct {
Assertion string `json:"assertion"`
}
err := db.ReadJSONFromMIME(h.rq.Header, h.rq.Body, ¶ms)
if err != nil {
return err
}
origin := h.server.config.Persona.Origin
if origin == "" {
base.Warn("Can't accept Persona logins: Server URL not configured")
return &base.HTTPError{http.StatusInternalServerError, "Server url not configured"}
}
// OK, now verify it:
base.Log("Persona: Verifying assertion %q for %q", params.Assertion, origin)
verifiedInfo, err := VerifyPersona(params.Assertion, origin)
if err != nil {
base.Log("Persona: Failed verify: %v", err)
return err
}
base.Log("Persona: Logged in %q!", verifiedInfo.Email)
createUserIfNeeded := h.server.config.Persona.Register
return h.makeSessionFromEmail(verifiedInfo.Email, createUserIfNeeded)
}
示例13: readDocument
func (h *handler) readDocument() (db.Body, error) {
contentType, attrs, _ := mime.ParseMediaType(h.rq.Header.Get("Content-Type"))
switch contentType {
case "", "application/json":
return h.readJSON()
case "multipart/related":
if DebugMultipart {
raw, err := ioutil.ReadAll(h.rq.Body)
if err != nil {
return nil, err
}
reader := multipart.NewReader(bytes.NewReader(raw), attrs["boundary"])
body, err := db.ReadMultipartDocument(reader)
if err != nil {
ioutil.WriteFile("GatewayPUT.mime", raw, 0600)
base.Warn("Error reading MIME data: copied to file GatewayPUT.mime")
}
return body, err
} else {
reader := multipart.NewReader(h.rq.Body, attrs["boundary"])
return db.ReadMultipartDocument(reader)
}
}
return nil, &base.HTTPError{http.StatusUnsupportedMediaType, "Invalid content type " + contentType}
}
示例14: UnmarshalJSON
func (tree RevTree) UnmarshalJSON(inputjson []byte) (err error) {
if tree == nil {
base.Warn("No RevTree for input %q", inputjson)
return nil
}
var rep revTreeList
err = json.Unmarshal(inputjson, &rep)
if err != nil {
return
}
for i, revid := range rep.Revs {
info := RevInfo{ID: revid}
if rep.Bodies != nil && len(rep.Bodies[i]) > 0 {
info.Body = []byte(rep.Bodies[i])
}
if rep.Channels != nil {
info.Channels = rep.Channels[i]
}
parentIndex := rep.Parents[i]
if parentIndex >= 0 {
info.Parent = rep.Revs[parentIndex]
}
tree[revid] = &info
}
if rep.Deleted != nil {
for _, i := range rep.Deleted {
info := tree[rep.Revs[i]]
info.Deleted = true //because tree[rep.Revs[i]].Deleted=true is a compile error
tree[rep.Revs[i]] = info
}
}
return
}
示例15: queryAllDocs
func (db *Database) queryAllDocs(reduce bool) (walrus.ViewResult, error) {
opts := Body{"stale": false, "reduce": reduce}
vres, err := db.Bucket.View("sync_housekeeping", "all_docs", opts)
if err != nil {
base.Warn("all_docs got error: %v", err)
}
return vres, err
}