No pointers, different types, prepare functions, crush

master
Alexey Kostin 2019-02-19 10:16:11 +03:00
parent 7073cc64df
commit 7b73a20d34
4 changed files with 269 additions and 141 deletions

View File

@ -7,8 +7,9 @@ import (
"time" "time"
) )
func get_pool_size(cephconn *Cephconnection, params *Params) *Monanswer { func get_pool_size(cephconn *Cephconnection, params Params) Poolinfo {
monjson, err := json.Marshal(Moncommand{Prefix: "osd pool get", Pool: params.pool, Format: "json", Var: "size"}) monjson, err := json.Marshal(map[string]string{"prefix": "osd pool get", "pool": params.pool,
"format": "json", "var": "size"})
if err != nil { if err != nil {
log.Fatalf("Can't marshal json mon query. Error: %v", err) log.Fatalf("Can't marshal json mon query. Error: %v", err)
} }
@ -18,16 +19,16 @@ func get_pool_size(cephconn *Cephconnection, params *Params) *Monanswer {
log.Fatalf("Failed exec monCommand. Error: %v", err) log.Fatalf("Failed exec monCommand. Error: %v", err)
} }
monanswer := Monanswer{} monanswer := Poolinfo{}
if err := json.Unmarshal([]byte(monrawanswer), &monanswer); err != nil { if err := json.Unmarshal([]byte(monrawanswer), &monanswer); err != nil {
log.Fatalf("Can't parse monitor answer. Error: %v", err) log.Fatalf("Can't parse monitor answer. Error: %v", err)
} }
return &monanswer return monanswer
} }
func get_pg_by_pool(cephconn *Cephconnection, params *Params) *[]PlacementGroup { func get_pg_by_pool(cephconn *Cephconnection, params Params) []PlacementGroup {
monjson, err := json.Marshal(Moncommand{Prefix: "pg ls-by-pool", Poolstr: params.pool, Format: "json"}) monjson, err := json.Marshal(map[string]string{"prefix": "pg ls-by-pool", "poolstr": params.pool, "format": "json"})
if err != nil { if err != nil {
log.Fatalf("Can't marshal json mon query. Error: %v", err) log.Fatalf("Can't marshal json mon query. Error: %v", err)
} }
@ -40,9 +41,17 @@ func get_pg_by_pool(cephconn *Cephconnection, params *Params) *[]PlacementGroup
if err := json.Unmarshal([]byte(monrawanswer), &monanswer); err != nil { if err := json.Unmarshal([]byte(monrawanswer), &monanswer); err != nil {
log.Fatalf("Can't parse monitor answer. Error: %v", err) log.Fatalf("Can't parse monitor answer. Error: %v", err)
} }
return &monanswer return monanswer
} }
//func get_crush_dump(params Params, cephconn *Cephconnection) OsdCrushDump {
//
//}
//func get_acting_osd(params Params, ) map[string]float64 {
//
//}
func main() { func main() {
params := Route() params := Route()
cephconn := connectioninit(params) cephconn := connectioninit(params)
@ -51,11 +60,6 @@ func main() {
// https://tracker.ceph.com/issues/24114 // https://tracker.ceph.com/issues/24114
time.Sleep(time.Millisecond * 100) time.Sleep(time.Millisecond * 100)
stats, _ := cephconn.ioctx.GetPoolStats()
log.Println(stats)
log.Printf("%v\n", params.blocksize)
var buffs [][]byte var buffs [][]byte
for i := 0; i < 2*params.threadsCount; i++ { for i := 0; i < 2*params.threadsCount; i++ {
buffs = append(buffs, make([]byte, params.blocksize)) buffs = append(buffs, make([]byte, params.blocksize))
@ -67,13 +71,18 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
} }
monanswersize := get_pool_size(cephconn, params) poolinfo := get_pool_size(cephconn, params)
if monanswersize.Size != 1 { if poolinfo.Size != 1 {
log.Fatalf("Pool size must be 1. Current size for pool %v is %v. Don't forget that it must be useless pool (not production). Do:\n # ceph osd pool set %v min_size 1\n # ceph osd pool set %v size 1", log.Fatalf("Pool size must be 1. Current size for pool %v is %v. Don't forget that it must be useless pool (not production). Do:\n # ceph osd pool set %v min_size 1\n # ceph osd pool set %v size 1",
monanswersize.Pool, monanswersize.Size, monanswersize.Pool, monanswersize.Pool) poolinfo.Pool, poolinfo.Size, poolinfo.Pool, poolinfo.Pool)
} }
placementGroups := get_pg_by_pool(cephconn, params) placementGroups := get_pg_by_pool(cephconn, params)
log.Println(placementGroups) for _, value := range placementGroups {
log.Printf("%+v\n", value)
}
} }
//TODO Получить структуру пула (osd dump), рул. Получить все рулы (osd crush dump). Разобрать краш карту, получить список осд.
//TODO получить список PG, если не все находятся на нужных OSD выкинуть эксепшн.

View File

@ -6,7 +6,7 @@ import (
"os" "os"
) )
func connectioninit(params *Params) *Cephconnection { func connectioninit(params Params) *Cephconnection {
cephconn := &Cephconnection{} cephconn := &Cephconnection{}
var err error var err error
if _, err := os.Stat(params.config); os.IsNotExist(err) { if _, err := os.Stat(params.config); os.IsNotExist(err) {

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
) )
func Route() *Params { func Route() Params {
params := Params{} params := Params{}
gnuflag.DurationVar(&params.duration, "duration", 30, gnuflag.DurationVar(&params.duration, "duration", 30,
"Time limit for each test in seconds") "Time limit for each test in seconds")
@ -61,5 +61,5 @@ func Route() *Params {
log.Println("Can't convert defined block size. 4K block size will be used\n") log.Println("Can't convert defined block size. 4K block size will be used\n")
params.blocksize = 4096 params.blocksize = 4096
} }
return &params return params
} }

363
types.go
View File

@ -18,15 +18,7 @@ type Cephconnection struct {
ioctx *rados.IOContext ioctx *rados.IOContext
} }
type Moncommand struct { type Poolinfo struct {
Prefix string `json:"prefix"`
Pool string `json:"pool"`
Format string `json:"format"`
Var string `json:"var,omitempty"`
Poolstr string `json:"poolstr,omitempty"`
}
type Monanswer struct {
Pool string `json:"pool,omitempty"` Pool string `json:"pool,omitempty"`
PoolId int `json:"pool_id,omitempty"` PoolId int `json:"pool_id,omitempty"`
Size int `json:"size,omitempty"` Size int `json:"size,omitempty"`
@ -34,120 +26,247 @@ type Monanswer struct {
func (times *PlacementGroup) StringsToTimes() { func (times *PlacementGroup) StringsToTimes() {
const LongForm = "2006-01-02 15:04:05.000000" const LongForm = "2006-01-02 15:04:05.000000"
times.Last_fresh, _ = time.Parse(LongForm, times.Last_fresh_str) times.LastFreshT, _ = time.Parse(LongForm, times.LastFresh)
times.Last_change, _ = time.Parse(LongForm, times.Last_fresh_str) times.LastChangeT, _ = time.Parse(LongForm, times.LastChange)
times.Last_active, _ = time.Parse(LongForm, times.Last_active_str) times.LastActiveT, _ = time.Parse(LongForm, times.LastActive)
times.Last_peered, _ = time.Parse(LongForm, times.Last_peered_str) times.LastPeeredT, _ = time.Parse(LongForm, times.LastPeered)
times.Last_clean, _ = time.Parse(LongForm, times.Last_clean_str) times.LastCleanT, _ = time.Parse(LongForm, times.LastClean)
times.Last_became_active, _ = time.Parse(LongForm, times.Last_became_active_str) times.LastBecameActiveT, _ = time.Parse(LongForm, times.LastBecameActive)
times.Last_became_peered, _ = time.Parse(LongForm, times.Last_became_peered_str) times.LastBecamePeeredT, _ = time.Parse(LongForm, times.LastBecamePeered)
times.Last_unstale, _ = time.Parse(LongForm, times.Last_unstale_str) times.LastUnstaleT, _ = time.Parse(LongForm, times.LastUnstale)
times.Last_undegraded, _ = time.Parse(LongForm, times.Last_undegraded_str) times.LastUndegradedT, _ = time.Parse(LongForm, times.LastUndegraded)
times.Last_fullsized, _ = time.Parse(LongForm, times.Last_fullsized_str) times.LastFullsizedT, _ = time.Parse(LongForm, times.LastFullsized)
times.Last_deep_scrub_stamp, _ = time.Parse(LongForm, times.Last_deep_scrub_stamp_str) times.LastDeepScrubStampT, _ = time.Parse(LongForm, times.LastDeepScrubStamp)
times.Last_deep_scrub, _ = time.Parse(LongForm, times.Last_deep_scrub_str) times.LastDeepScrubT, _ = time.Parse(LongForm, times.LastDeepScrub)
times.Last_clean_scrub_stamp, _ = time.Parse(LongForm, times.Last_clean_scrub_stamp_str) times.LastCleanScrubStampT, _ = time.Parse(LongForm, times.LastCleanScrubStamp)
times.Last_scrub_stamp, _ = time.Parse(LongForm, times.Last_scrub_stamp_str) times.LastScrubStampT, _ = time.Parse(LongForm, times.LastScrubStamp)
times.Last_scrub, _ = time.Parse(LongForm, times.Last_scrub_str) times.LastScrubT, _ = time.Parse(LongForm, times.LastScrub)
}
type OsdCrushDump struct {
Buckets []struct {
Alg string `json:"alg"`
Hash string `json:"hash"`
ID int64 `json:"id"`
Items []struct {
ID int64 `json:"id"`
Pos int64 `json:"pos"`
Weight int64 `json:"weight"`
} `json:"items"`
Name string `json:"name"`
TypeID int64 `json:"type_id"`
TypeName string `json:"type_name"`
Weight int64 `json:"weight"`
} `json:"buckets"`
ChooseArgs struct{} `json:"choose_args"`
Devices []struct {
Class string `json:"class"`
ID int64 `json:"id"`
Name string `json:"name"`
} `json:"devices"`
Rules []struct {
MaxSize int64 `json:"max_size"`
MinSize int64 `json:"min_size"`
RuleID int64 `json:"rule_id"`
RuleName string `json:"rule_name"`
Ruleset int64 `json:"ruleset"`
Steps []struct {
Item int64 `json:"item"`
ItemName string `json:"item_name"`
Num int64 `json:"num"`
Op string `json:"op"`
Type string `json:"type"`
} `json:"steps"`
Type int64 `json:"type"`
} `json:"rules"`
Tunables struct {
AllowedBucketAlgs int64 `json:"allowed_bucket_algs"`
ChooseLocalFallbackTries int64 `json:"choose_local_fallback_tries"`
ChooseLocalTries int64 `json:"choose_local_tries"`
ChooseTotalTries int64 `json:"choose_total_tries"`
ChooseleafDescendOnce int64 `json:"chooseleaf_descend_once"`
ChooseleafStable int64 `json:"chooseleaf_stable"`
ChooseleafVaryR int64 `json:"chooseleaf_vary_r"`
HasV2Rules int64 `json:"has_v2_rules"`
HasV3Rules int64 `json:"has_v3_rules"`
HasV4Buckets int64 `json:"has_v4_buckets"`
HasV5Rules int64 `json:"has_v5_rules"`
LegacyTunables int64 `json:"legacy_tunables"`
MinimumRequiredVersion string `json:"minimum_required_version"`
OptimalTunables int64 `json:"optimal_tunables"`
Profile string `json:"profile"`
RequireFeatureTunables int64 `json:"require_feature_tunables"`
RequireFeatureTunables2 int64 `json:"require_feature_tunables2"`
RequireFeatureTunables3 int64 `json:"require_feature_tunables3"`
RequireFeatureTunables5 int64 `json:"require_feature_tunables5"`
StrawCalcVersion int64 `json:"straw_calc_version"`
} `json:"tunables"`
Types []struct {
Name string `json:"name"`
TypeID int64 `json:"type_id"`
} `json:"types"`
}
type OsdDump struct {
Buckets []struct {
Alg string `json:"alg"`
Hash string `json:"hash"`
ID int64 `json:"id"`
Items []struct {
ID int64 `json:"id"`
Pos int64 `json:"pos"`
Weight int64 `json:"weight"`
} `json:"items"`
Name string `json:"name"`
TypeID int64 `json:"type_id"`
TypeName string `json:"type_name"`
Weight int64 `json:"weight"`
} `json:"buckets"`
ChooseArgs struct{} `json:"choose_args"`
Devices []struct {
Class string `json:"class"`
ID int64 `json:"id"`
Name string `json:"name"`
} `json:"devices"`
Rules []struct {
MaxSize int64 `json:"max_size"`
MinSize int64 `json:"min_size"`
RuleID int64 `json:"rule_id"`
RuleName string `json:"rule_name"`
Ruleset int64 `json:"ruleset"`
Steps []struct {
Item int64 `json:"item"`
ItemName string `json:"item_name"`
Num int64 `json:"num"`
Op string `json:"op"`
Type string `json:"type"`
} `json:"steps"`
Type int64 `json:"type"`
} `json:"rules"`
Tunables struct {
AllowedBucketAlgs int64 `json:"allowed_bucket_algs"`
ChooseLocalFallbackTries int64 `json:"choose_local_fallback_tries"`
ChooseLocalTries int64 `json:"choose_local_tries"`
ChooseTotalTries int64 `json:"choose_total_tries"`
ChooseleafDescendOnce int64 `json:"chooseleaf_descend_once"`
ChooseleafStable int64 `json:"chooseleaf_stable"`
ChooseleafVaryR int64 `json:"chooseleaf_vary_r"`
HasV2Rules int64 `json:"has_v2_rules"`
HasV3Rules int64 `json:"has_v3_rules"`
HasV4Buckets int64 `json:"has_v4_buckets"`
HasV5Rules int64 `json:"has_v5_rules"`
LegacyTunables int64 `json:"legacy_tunables"`
MinimumRequiredVersion string `json:"minimum_required_version"`
OptimalTunables int64 `json:"optimal_tunables"`
Profile string `json:"profile"`
RequireFeatureTunables int64 `json:"require_feature_tunables"`
RequireFeatureTunables2 int64 `json:"require_feature_tunables2"`
RequireFeatureTunables3 int64 `json:"require_feature_tunables3"`
RequireFeatureTunables5 int64 `json:"require_feature_tunables5"`
StrawCalcVersion int64 `json:"straw_calc_version"`
} `json:"tunables"`
Types []struct {
Name string `json:"name"`
TypeID int64 `json:"type_id"`
} `json:"types"`
} }
type PlacementGroup struct { type PlacementGroup struct {
Pgid string `json:"pgid"` Acting []int64 `json:"acting"`
Version string `json:"version"` ActingPrimary int64 `json:"acting_primary"`
Reported_seq string `json:"reported_seq"` BlockedBy []interface{} `json:"blocked_by"`
Reported_epoch string `json:"reported_epoch"` Created int64 `json:"created"`
State string `json:"state"` DirtyStatsInvalid bool `json:"dirty_stats_invalid"`
Last_fresh_str string `json:"last_fresh"` HitsetBytesStatsInvalid bool `json:"hitset_bytes_stats_invalid"`
Last_fresh time.Time HitsetStatsInvalid bool `json:"hitset_stats_invalid"`
Last_change_str string `json:"last_change"` LastActive string `json:"last_active"`
Last_change time.Time LastActiveT time.Time
Last_active_str string `json:"last_active"` LastBecameActive string `json:"last_became_active"`
Last_active time.Time LastBecameActiveT time.Time
Last_peered_str string `json:"last_peered"` LastBecamePeered string `json:"last_became_peered"`
Last_peered time.Time LastBecamePeeredT time.Time
Last_clean_str string `json:"last_clean"` LastChange string `json:"last_change"`
Last_clean time.Time LastChangeT time.Time
Last_became_active_str string `json:"last_became_active"` LastClean string `json:"last_clean"`
Last_became_active time.Time LastCleanT time.Time
Last_became_peered_str string `json:"last_became_peered"` LastCleanScrubStamp string `json:"last_clean_scrub_stamp"`
Last_became_peered time.Time LastCleanScrubStampT time.Time
Last_unstale_str string `json:"last_unstale"` LastDeepScrub string `json:"last_deep_scrub"`
Last_unstale time.Time LastDeepScrubT time.Time
Last_undegraded_str string `json:"last_undegraded"` LastDeepScrubStamp string `json:"last_deep_scrub_stamp"`
Last_undegraded time.Time LastDeepScrubStampT time.Time
Last_fullsized_str string `json:"last_fullsized"` LastEpochClean int64 `json:"last_epoch_clean"`
Last_fullsized time.Time LastFresh string `json:"last_fresh"`
Mapping_epoch float64 `json:"mapping_epoch"` LastFreshT time.Time
Log_start string `json:"log_start"` LastFullsized string `json:"last_fullsized"`
Ondisk_log_start string `json:"ondisk_log_start"` LastFullsizedT time.Time
Created float64 `json:"created"` LastPeered string `json:"last_peered"`
Last_epoch_clean float64 `json:"last_epoch_clean"` LastPeeredT time.Time
Parent string `json:"parent"` LastScrub string `json:"last_scrub"`
Parent_split_bits float64 `json:"parent_split_bits"` LastScrubT time.Time
Last_scrub_str string `json:"last_scrub"` LastScrubStamp string `json:"last_scrub_stamp"`
Last_scrub time.Time LastScrubStampT time.Time
Last_scrub_stamp_str string `json:"last_scrub_stamp"` LastUndegraded string `json:"last_undegraded"`
Last_scrub_stamp time.Time LastUndegradedT time.Time
Last_deep_scrub_str string `json:"last_deep_scrub"` LastUnstale string `json:"last_unstale"`
Last_deep_scrub time.Time LastUnstaleT time.Time
Last_deep_scrub_stamp_str string `json:"last_deep_scrub_stamp"` LogSize int64 `json:"log_size"`
Last_deep_scrub_stamp time.Time LogStart string `json:"log_start"`
Last_clean_scrub_stamp_str string `json:"last_clean_scrub_stamp"` ManifestStatsInvalid bool `json:"manifest_stats_invalid"`
Last_clean_scrub_stamp time.Time MappingEpoch int64 `json:"mapping_epoch"`
Log_size float64 `json:"log_size"` OmapStatsInvalid bool `json:"omap_stats_invalid"`
Ondisk_log_size float64 `json:"ondisk_log_size"` OndiskLogSize int64 `json:"ondisk_log_size"`
Stats_invalid bool `json:"stats_invalid"` OndiskLogStart string `json:"ondisk_log_start"`
Dirty_stats_invalid bool `json:"dirty_stats_invalid"` Parent string `json:"parent"`
Omap_stats_invalid bool `json:"omap_stats_invalid"` ParentSplitBits int64 `json:"parent_split_bits"`
Hitset_stats_invalid bool `json:"hitset_stats_invalid"` Pgid string `json:"pgid"`
Hitset_bytes_stats_invalid bool `json:"hitset_bytes_stats_invalid"` PinStatsInvalid bool `json:"pin_stats_invalid"`
Pin_stats_invalid bool `json:"pin_stats_invalid"` PurgedSnaps []interface{} `json:"purged_snaps"`
Manifest_stats_invalid bool `json:"manifest_stats_invalid"` ReportedEpoch string `json:"reported_epoch"`
Snaptrimq_len float64 `json:"snaptrimq_len"` ReportedSeq string `json:"reported_seq"`
Stat_sum StatSum `json:"stat_sum"` SnaptrimqLen int64 `json:"snaptrimq_len"`
Up []float64 `json:"up"` StatSum struct {
Acting []float64 `json:"acting"` NumBytes int64 `json:"num_bytes"`
Blocked_by []float64 `json:"blocked_by"` NumBytesHitSetArchive int64 `json:"num_bytes_hit_set_archive"`
Up_primary float64 `json:"up_primary"` NumBytesRecovered int64 `json:"num_bytes_recovered"`
Acting_primary float64 `json:"acting_primary"` NumDeepScrubErrors int64 `json:"num_deep_scrub_errors"`
Purged_snaps []string `json:"purged_snaps"` NumEvict int64 `json:"num_evict"`
} NumEvictKb int64 `json:"num_evict_kb"`
NumEvictModeFull int64 `json:"num_evict_mode_full"`
type StatSum struct { NumEvictModeSome int64 `json:"num_evict_mode_some"`
Num_objects float64 `json:"num_objects"` NumFlush int64 `json:"num_flush"`
Num_object_clones float64 `json:"num_object_clones"` NumFlushKb int64 `json:"num_flush_kb"`
Num_object_copies float64 `json:"num_object_copies"` NumFlushModeHigh int64 `json:"num_flush_mode_high"`
Num_objects_missing_on_primary float64 `json:"num_objects_missing_on_primary"` NumFlushModeLow int64 `json:"num_flush_mode_low"`
Num_objects_missing float64 `json:"num_objects_missing"` NumKeysRecovered int64 `json:"num_keys_recovered"`
Num_objects_degraded float64 `json:"num_objects_degraded"` NumLargeOmapObjects int64 `json:"num_large_omap_objects"`
Num_objects_misplaced float64 `json:"num_objects_misplaced"` NumLegacySnapsets int64 `json:"num_legacy_snapsets"`
Num_objects_unfound float64 `json:"num_objects_unfound"` NumObjectClones int64 `json:"num_object_clones"`
Num_objects_dirty float64 `json:"num_objects_dirty"` NumObjectCopies int64 `json:"num_object_copies"`
Num_whiteouts float64 `json:"num_whiteouts"` NumObjects int64 `json:"num_objects"`
Num_read float64 `json:"num_read"` NumObjectsDegraded int64 `json:"num_objects_degraded"`
Num_read_kb float64 `json:"num_read_kb"` NumObjectsDirty int64 `json:"num_objects_dirty"`
Num_write float64 `json:"num_write"` NumObjectsHitSetArchive int64 `json:"num_objects_hit_set_archive"`
Num_write_kb float64 `json:"num_write_kb"` NumObjectsManifest int64 `json:"num_objects_manifest"`
Num_scrub_errors float64 `json:"num_scrub_errors"` NumObjectsMisplaced int64 `json:"num_objects_misplaced"`
Num_shallow_scrub_errors float64 `json:"num_shallow_scrub_errors"` NumObjectsMissing int64 `json:"num_objects_missing"`
Num_deep_scrub_errors float64 `json:"num_deep_scrub_errors"` NumObjectsMissingOnPrimary int64 `json:"num_objects_missing_on_primary"`
Num_objects_recovered float64 `json:"num_objects_recovered"` NumObjectsOmap int64 `json:"num_objects_omap"`
Num_bytes_recovered float64 `json:"num_bytes_recovered"` NumObjectsPinned int64 `json:"num_objects_pinned"`
Num_keys_recovered float64 `json:"num_keys_recovered"` NumObjectsRecovered int64 `json:"num_objects_recovered"`
Num_objects_omap float64 `json:"num_objects_omap"` NumObjectsUnfound int64 `json:"num_objects_unfound"`
Num_objects_hit_set_archive float64 `json:"num_objects_hit_set_archive"` NumPromote int64 `json:"num_promote"`
Num_bytes_hit_set_archive float64 `json:"num_bytes_hit_set_archive"` NumRead int64 `json:"num_read"`
Num_flush float64 `json:"num_flush"` NumReadKb int64 `json:"num_read_kb"`
Num_flush_kb float64 `json:"num_flush_kb"` NumScrubErrors int64 `json:"num_scrub_errors"`
Num_evict float64 `json:"num_evict"` NumShallowScrubErrors int64 `json:"num_shallow_scrub_errors"`
Num_evict_kb float64 `json:"num_evict_kb"` NumWhiteouts int64 `json:"num_whiteouts"`
Num_promote float64 `json:"num_promote"` NumWrite int64 `json:"num_write"`
Num_flush_mode_high float64 `json:"num_flush_mode_high"` NumWriteKb int64 `json:"num_write_kb"`
Num_flush_mode_low float64 `json:"num_flush_mode_low"` } `json:"stat_sum"`
Num_evict_mode_some float64 `json:"num_evict_mode_some"` State string `json:"state"`
Num_evict_mode_full float64 `json:"num_evict_mode_full"` StatsInvalid bool `json:"stats_invalid"`
Num_objects_pinned float64 `json:"num_objects_pinned"` Up []int64 `json:"up"`
Num_legacy_snapsets float64 `json:"num_legacy_snapsets"` UpPrimary int64 `json:"up_primary"`
Num_large_omap_objects float64 `json:"num_large_omap_objects"` Version string `json:"version"`
Num_objects_manifest float64 `json:"num_objects_manifest"`
} }