Change controller calls that use stream metadata to instantly time out if unavailable, rather than waiting for availability

This commit is contained in:
Thulinma 2023-08-21 11:20:31 +02:00
parent f19899aed2
commit f3ba13d6bb
4 changed files with 16 additions and 16 deletions

View file

@ -901,13 +901,13 @@ namespace DTSC{
/// Initialize empty metadata, in master or slave mode. /// Initialize empty metadata, in master or slave mode.
/// If stream name is empty, slave mode is enforced. /// If stream name is empty, slave mode is enforced.
Meta::Meta(const std::string &_streamName, bool master){ Meta::Meta(const std::string &_streamName, bool master, bool autoBackOff){
if (!_streamName.size()){master = false;} if (!_streamName.size()){master = false;}
version = DTSH_VERSION; version = DTSH_VERSION;
streamMemBuf = 0; streamMemBuf = 0;
isMemBuf = false; isMemBuf = false;
isMaster = master; isMaster = master;
reInit(_streamName, master); reInit(_streamName, master, autoBackOff);
} }
/// Initialize metadata from given DTSH file in master mode. /// Initialize metadata from given DTSH file in master mode.
@ -926,12 +926,12 @@ namespace DTSC{
/// Calls clear(), then initializes freshly. /// Calls clear(), then initializes freshly.
/// If stream name is set, uses shared memory backing. /// If stream name is set, uses shared memory backing.
/// If stream name is empty, uses non-shared memory backing. /// If stream name is empty, uses non-shared memory backing.
void Meta::reInit(const std::string &_streamName, bool master){ void Meta::reInit(const std::string &_streamName, bool master, bool autoBackOff){
clear(); clear();
if (_streamName == ""){ if (_streamName == ""){
sBufMem(); sBufMem();
}else{ }else{
sBufShm(_streamName, DEFAULT_TRACK_COUNT, master); sBufShm(_streamName, DEFAULT_TRACK_COUNT, master, autoBackOff);
} }
streamInit(); streamInit();
} }
@ -1118,7 +1118,7 @@ namespace DTSC{
/// Initializes shared memory backed mode, with enough room for the given track count. /// Initializes shared memory backed mode, with enough room for the given track count.
/// Should not be called repeatedly, nor to switch modes. /// Should not be called repeatedly, nor to switch modes.
void Meta::sBufShm(const std::string &_streamName, size_t trackCount, bool master){ void Meta::sBufShm(const std::string &_streamName, size_t trackCount, bool master, bool autoBackOff){
isMaster = master; isMaster = master;
if (isMaster){HIGH_MSG("Creating meta page for stream %s", _streamName.c_str());} if (isMaster){HIGH_MSG("Creating meta page for stream %s", _streamName.c_str());}
@ -1142,7 +1142,7 @@ namespace DTSC{
streamPage.master = false; streamPage.master = false;
stream = Util::RelAccX(streamPage.mapped, false); stream = Util::RelAccX(streamPage.mapped, false);
}else{ }else{
streamPage.init(pageName, bufferSize, false, true); streamPage.init(pageName, bufferSize, false, autoBackOff);
if (!streamPage.mapped){ if (!streamPage.mapped){
INFO_MSG("Page %s not found", pageName); INFO_MSG("Page %s not found", pageName);
return; return;

View file

@ -284,11 +284,11 @@ namespace DTSC{
class Meta{ class Meta{
public: public:
Meta(const std::string &_streamName, const DTSC::Scan &src); Meta(const std::string &_streamName, const DTSC::Scan &src);
Meta(const std::string &_streamName = "", bool master = true); Meta(const std::string &_streamName = "", bool master = true, bool autoBackOff = true);
Meta(const std::string &_streamName, const std::string &fileName); Meta(const std::string &_streamName, const std::string &fileName);
~Meta(); ~Meta();
void reInit(const std::string &_streamName, bool master = true); void reInit(const std::string &_streamName, bool master = true, bool autoBackOff = true);
void reInit(const std::string &_streamName, const std::string &fileName); void reInit(const std::string &_streamName, const std::string &fileName);
void reInit(const std::string &_streamName, const DTSC::Scan &src); void reInit(const std::string &_streamName, const DTSC::Scan &src);
void addTrackFrom(const DTSC::Scan &src); void addTrackFrom(const DTSC::Scan &src);
@ -493,7 +493,7 @@ namespace DTSC{
protected: protected:
void sBufMem(size_t trackCount = DEFAULT_TRACK_COUNT); void sBufMem(size_t trackCount = DEFAULT_TRACK_COUNT);
void sBufShm(const std::string &_streamName, size_t trackCount = DEFAULT_TRACK_COUNT, bool master = true); void sBufShm(const std::string &_streamName, size_t trackCount = DEFAULT_TRACK_COUNT, bool master = true, bool autoBackOff = true);
void streamInit(size_t trackCount = DEFAULT_TRACK_COUNT); void streamInit(size_t trackCount = DEFAULT_TRACK_COUNT);
std::string streamName; std::string streamName;

View file

@ -1207,7 +1207,7 @@ void Controller::fillHasStats(JSON::Value &req, JSON::Value &rep){
jsonForEach(req, j){ jsonForEach(req, j){
if (j->asStringRef() == "clients"){rep[*it].append(clients[*it]);} if (j->asStringRef() == "clients"){rep[*it].append(clients[*it]);}
if (j->asStringRef() == "lastms"){ if (j->asStringRef() == "lastms"){
DTSC::Meta M(*it, false); DTSC::Meta M(*it, false, false);
if (M){ if (M){
uint64_t lms = 0; uint64_t lms = 0;
std::set<size_t> validTracks = M.getValidTracks(); std::set<size_t> validTracks = M.getValidTracks();
@ -1325,7 +1325,7 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){
}else if (j->asStringRef() == "packretrans"){ }else if (j->asStringRef() == "packretrans"){
F = it->second.packRetrans; F = it->second.packRetrans;
}else if (j->asStringRef() == "firstms"){ }else if (j->asStringRef() == "firstms"){
if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);}
if (M){ if (M){
uint64_t fms = 0; uint64_t fms = 0;
std::set<size_t> validTracks = M.getValidTracks(); std::set<size_t> validTracks = M.getValidTracks();
@ -1335,7 +1335,7 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){
F = fms; F = fms;
} }
}else if (j->asStringRef() == "lastms"){ }else if (j->asStringRef() == "lastms"){
if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);}
if (M){ if (M){
uint64_t lms = 0; uint64_t lms = 0;
std::set<size_t> validTracks = M.getValidTracks(); std::set<size_t> validTracks = M.getValidTracks();
@ -1345,15 +1345,15 @@ void Controller::fillActive(JSON::Value &req, JSON::Value &rep){
F = lms; F = lms;
} }
}else if (j->asStringRef() == "zerounix"){ }else if (j->asStringRef() == "zerounix"){
if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);}
if (M && M.getLive()){ if (M && M.getLive()){
F = (M.getBootMsOffset() + (Util::unixMS() - Util::bootMS())) / 1000; F = (M.getBootMsOffset() + (Util::unixMS() - Util::bootMS())) / 1000;
} }
}else if (j->asStringRef() == "health"){ }else if (j->asStringRef() == "health"){
if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);}
if (M){M.getHealthJSON(F);} if (M){M.getHealthJSON(F);}
}else if (j->asStringRef() == "tracks"){ }else if (j->asStringRef() == "tracks"){
if (!M || M.getStreamName() != it->first){M.reInit(it->first, false);} if (!M || M.getStreamName() != it->first){M.reInit(it->first, false, false);}
if (M){ if (M){
F = (uint64_t)M.getValidTracks().size(); F = (uint64_t)M.getValidTracks().size();
} }

View file

@ -353,7 +353,7 @@ namespace Controller{
Util::sanitizeName(cleaned); Util::sanitizeName(cleaned);
std::string strmSource; std::string strmSource;
if (Util::getStreamStatus(cleaned) != STRMSTAT_OFF){ if (Util::getStreamStatus(cleaned) != STRMSTAT_OFF){
DTSC::Meta M(cleaned, false); DTSC::Meta M(cleaned, false, false);
if (M && M.getSource().size()){strmSource = M.getSource();} if (M && M.getSource().size()){strmSource = M.getSource();}
} }
if (!strmSource.size()){ if (!strmSource.size()){