cubefs

Форк
0
/
wrap_post.go 
79 строк · 1.9 Кб
1
// Copyright 2018 The CubeFS Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12
// implied. See the License for the specific language governing
13
// permissions and limitations under the License.
14

15
package datanode
16

17
import (
18
	"sync/atomic"
19

20
	"github.com/cubefs/cubefs/proto"
21
	"github.com/cubefs/cubefs/repl"
22
	"github.com/cubefs/cubefs/storage"
23
)
24

25
func (s *DataNode) Post(p *repl.Packet) error {
26
	if p.IsMasterCommand() {
27
		p.NeedReply = true
28
	}
29
	if p.IsReadOperation() && p.AfterPre {
30
		p.NeedReply = false
31
	}
32
	s.cleanupPkt(p)
33
	s.addMetrics(p)
34
	return nil
35
}
36

37
func (s *DataNode) cleanupPkt(p *repl.Packet) {
38
	if p.IsMasterCommand() {
39
		return
40
	}
41
	if !p.IsLeaderPacket() {
42
		return
43
	}
44
	s.releaseExtent(p)
45
}
46

47
func (s *DataNode) releaseExtent(p *repl.Packet) {
48
	if p == nil || !storage.IsTinyExtent(p.ExtentID) || p.ExtentID <= 0 || atomic.LoadInt32(&p.IsReleased) == IsReleased {
49
		return
50
	}
51
	if !proto.IsTinyExtentType(p.ExtentType) || !p.IsLeaderPacket() || !p.IsNormalWriteOperation() || !p.IsForwardPkt() {
52
		return
53
	}
54
	if p.Object == nil {
55
		return
56
	}
57
	partition := p.Object.(*DataPartition)
58
	store := partition.ExtentStore()
59
	if p.IsErrPacket() {
60
		store.SendToBrokenTinyExtentC(p.ExtentID)
61
	} else {
62
		store.SendToAvailableTinyExtentC(p.ExtentID)
63
	}
64
	atomic.StoreInt32(&p.IsReleased, IsReleased)
65
}
66

67
func (s *DataNode) addMetrics(p *repl.Packet) {
68
	if p.IsMasterCommand() || p.ShallDegrade() {
69
		return
70
	}
71
	p.AfterTp()
72
	if p.Object == nil {
73
		return
74
	}
75
	partition := p.Object.(*DataPartition)
76
	if partition == nil {
77
		return
78
	}
79
}
80

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.