You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
7 months ago
7 months ago
11 months ago
  1. package broker
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/glog"
  5. "github.com/seaweedfs/seaweedfs/weed/mq/topic"
  6. "github.com/seaweedfs/seaweedfs/weed/util/log_buffer"
  7. "sync/atomic"
  8. "time"
  9. )
  10. func (b *MessageQueueBroker) genLogFlushFunc(t topic.Topic, p topic.Partition) log_buffer.LogFlushFuncType {
  11. partitionDir := topic.PartitionDir(t, p)
  12. return func(logBuffer *log_buffer.LogBuffer, startTime, stopTime time.Time, buf []byte) {
  13. if len(buf) == 0 {
  14. return
  15. }
  16. startTime, stopTime = startTime.UTC(), stopTime.UTC()
  17. targetFile := fmt.Sprintf("%s/%s", partitionDir, startTime.Format(topic.TIME_FORMAT))
  18. // TODO append block with more metadata
  19. for {
  20. if err := b.appendToFile(targetFile, buf); err != nil {
  21. glog.V(0).Infof("metadata log write failed %s: %v", targetFile, err)
  22. time.Sleep(737 * time.Millisecond)
  23. } else {
  24. break
  25. }
  26. }
  27. atomic.StoreInt64(&logBuffer.LastFlushTsNs, stopTime.UnixNano())
  28. b.accessLock.Lock()
  29. defer b.accessLock.Unlock()
  30. if localPartition := b.localTopicManager.GetLocalPartition(t, p); localPartition != nil {
  31. localPartition.NotifyLogFlushed(logBuffer.LastFlushTsNs)
  32. }
  33. glog.V(0).Infof("flushing at %d to %s size %d", logBuffer.LastFlushTsNs, targetFile, len(buf))
  34. }
  35. }