sentinel | Scalable realtime stream mining

 by   amir-rahnama Java Updated: 2 years ago - v0.0.1-alpha License: No License

Download this library from

Build Applications

kandi X-RAY | sentinel REVIEW AND RATINGS

Sentinel is project written in Java to perform real-time stream mining on Twitter Public Stream using SAMOA and Apache Storm. Sentinel is a distributed system that aims to use new distributed algorithms. Currently Sentinel only supports real-time distributed classifications. See Tasks section for details on how to work with Sentinel.

kandi-support
Support

  • sentinel has a highly active ecosystem.
  • It has 15 star(s) with 5 fork(s).
  • It had no major release in the last 12 months.
  • It has a positive sentiment in the developer community.

quality kandi
Quality

  • sentinel has 0 bugs and 0 code smells.

security
Security

  • sentinel has 2 vulnerability issues reported (0 critical, 1 high, 1 medium, 0 low).
  • sentinel code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.

license
License

  • sentinel does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.

build
Reuse

  • sentinel releases are available to install and integrate.
  • sentinel has no build file. You will be need to create the build yourself to build the component from source.
  • sentinel saves you 387 person hours of effort in developing the same functionality from scratch.
  • It has 922 lines of code, 106 functions and 9 files with 0 % test coverage
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Top functions reviewed by kandi - BETA

kandi has reviewed sentinel and discovered the below as its top functions. This is intended to give you an instant insight into sentinel implemented functionality, and help decide if they suit your requirements.

  • Checks if there is one instance .
  • Gets the instance .
  • Update the position of a node .
  • remove Emotions from the message .
  • Gets the number of tokens in the document .
  • Read last tweet from file .
  • Adds zeros to the current node .
  • Sets up twitter stream listener
  • Sets the filtered message based on language filter
  • Adds a token .

sentinel Key Features

This components transforms tweet texts into an sparse feature vectors and only keeps frequent features in memory only.

sentinel examples and code snippets

  • Install
  • Build
  • Real-time Sentiment Analysis on Twitter Public Stream
  • Configuration by Code
  • Find the alphabetically first String using Java
  • Redis sentinel HA on Kubernetes
  • Why when I execute my Java program does it not convert the first user input, but does every user input after?
  • Rasterio " does not exist in the file system, and is not recognized as a supported dataset name."
  • How to implement a resetting function for custom generator in c++?
  • How do I connect kqlmagic to more than one Log Analytics workspace at the same time?
  • How to display a 32-bit DIV result stored in DX:AX
  • Infinite scroll component using GraphQL and IntersectionObserver
  • Removing duplicates from python array
  • Is there a more efficient way in performing repeated tasks in my batch file?

Install

git clone https://github.com/ambodi/samoa

Build

mvn clean install

Real-time Sentiment Analysis on Twitter Public Stream

bin/samoa local target/SAMOA-Local-0.3.0-SNAPSHOT.jar "PrequentialEvaluation -d /tmp/dump.csv -i 1000000 -f 100000 -l (classifiers.trees.VerticalHoeffdingTree -p 4) -s com.yahoo.labs.samoa.sentinel.model.TwitterStreamInstance"

Configuration by Code

public static void main( String[] args ) {
    PrequentialEvaluation pe = new PrequentialEvaluation();
    pe.setFactory(new SimpleComponentFactory());

    pe.dumpFileOption.setValueViaCLIString("/tmp/dump.csv");
    pe.instanceLimitOption.setValue(50);
    pe.sampleFrequencyOption.setValue(5);
    pe.learnerOption.setValueViaCLIString("classifiers.trees.VerticalHoeffdingTree -p 1");
    pe.streamTrainOption.setValueViaCLIString(TwitterStreamInstance.class.getName());

    pe.init();
}

Find the alphabetically first String using Java

public class HelloWorld{

     public static void main(String []args){
        String word;
        Scanner sc = new Scanner(System.in);
        String first = null;
        
        while(!(word = sc.nextLine()).equals("END")) {
            if(first == null || word.compareTo(first) < 0) {
                first = word;
            }
        }
        
        System.out.println(first);
     }
}

Redis sentinel HA on Kubernetes

$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...
-----------------------
$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml
# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...
$ helm install redis-sentinel bitnami/redis --values values.yaml
$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m
$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel
$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...
    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379
$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...

Why when I execute my Java program does it not convert the first user input, but does every user input after?

// Import scanner Object
import java.util.Scanner;
// Import text Object for formatting
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class CurrencyConversion {
    public static void main (String [] args) 
    {
        // Identify Scanner 
        Scanner input = new Scanner(System.in);
        
        // Declare variables
        double USDtoJPY; //JPY stands for Japanese Yen
        double USD;// USD stands for US Dollar
        int count = 0;
        
        // Formatting input
        DecimalFormat f = new DecimalFormat ("#,###.##");
        
        // Ask user to input exchange rate from JPY to USD
        System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
        USDtoJPY = input.nextDouble();
        
        // Ask user to input how many USD dollars they want to convert
        System.out.println("Enter amount in USD to convert: (0 to Quit)"); 
        USD = input.nextDouble();
        
        // Process Data until sentinel is entered
        while (USD != 0)
        {
            count++;
        
            if (count > 0)
            {
                double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
                System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
            }
            else
            {
                System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
            }
            USD = input.nextDouble(); // move this here
        }
    } 
}
import java.util.Scanner;
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class DummyClass {
  public static void main (String [] args)
  {
    // Identify Scanner
    Scanner input = new Scanner(System.in);

    // Declare variables
    double USDtoJPY; //JPY stands for Japanese Yen
    double USD;// USD stands for US Dollar

    // Formatting input
    DecimalFormat f = new DecimalFormat ("#,###.##");

    // Ask user to input exchange rate from JPY to USD
    System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
    USDtoJPY = input.nextDouble();

    // Ask user to input how many USD dollars they want to convert
    System.out.println("Enter amount in USD to convert: (0 to Quit)");

    // Process Data until sentinel is entered
    do {
      USD = input.nextDouble();

      if (USD > 0)
      {
        double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
        System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
      }
      else
      {
        System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
      }
    } while (USD != 0);
  }
}
-----------------------
// Import scanner Object
import java.util.Scanner;
// Import text Object for formatting
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class CurrencyConversion {
    public static void main (String [] args) 
    {
        // Identify Scanner 
        Scanner input = new Scanner(System.in);
        
        // Declare variables
        double USDtoJPY; //JPY stands for Japanese Yen
        double USD;// USD stands for US Dollar
        int count = 0;
        
        // Formatting input
        DecimalFormat f = new DecimalFormat ("#,###.##");
        
        // Ask user to input exchange rate from JPY to USD
        System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
        USDtoJPY = input.nextDouble();
        
        // Ask user to input how many USD dollars they want to convert
        System.out.println("Enter amount in USD to convert: (0 to Quit)"); 
        USD = input.nextDouble();
        
        // Process Data until sentinel is entered
        while (USD != 0)
        {
            count++;
        
            if (count > 0)
            {
                double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
                System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
            }
            else
            {
                System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
            }
            USD = input.nextDouble(); // move this here
        }
    } 
}
import java.util.Scanner;
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class DummyClass {
  public static void main (String [] args)
  {
    // Identify Scanner
    Scanner input = new Scanner(System.in);

    // Declare variables
    double USDtoJPY; //JPY stands for Japanese Yen
    double USD;// USD stands for US Dollar

    // Formatting input
    DecimalFormat f = new DecimalFormat ("#,###.##");

    // Ask user to input exchange rate from JPY to USD
    System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
    USDtoJPY = input.nextDouble();

    // Ask user to input how many USD dollars they want to convert
    System.out.println("Enter amount in USD to convert: (0 to Quit)");

    // Process Data until sentinel is entered
    do {
      USD = input.nextDouble();

      if (USD > 0)
      {
        double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
        System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
      }
      else
      {
        System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
      }
    } while (USD != 0);
  }
}

Rasterio &quot; does not exist in the file system, and is not recognized as a supported dataset name.&quot;

s3sr = boto3.resource('s3')
bucket='usgs-landsat'
prefix = 'collection02/'
keys_list = []
paginator = s3sr.meta.client.get_paginator('list_objects_v2')
for page in  paginator.paginate(Bucket=bucket, Prefix=prefix, Delimiter='/', RequestPayer='requester'):
    keys = [content['Key'] for content in page.get('Contents')]
    keys_list.extend(keys)
len(keys_list)

# keys_list 
['collection02/catalog.json',
 'collection02/landsat-c2l1.json',
 'collection02/landsat-c2l2-sr.json',
 'collection02/landsat-c2l2-st.json',
 'collection02/landsat-c2l2alb-bt.json',
 'collection02/landsat-c2l2alb-sr.json',
 'collection02/landsat-c2l2alb-st.json',
 'collection02/landsat-c2l2alb-ta.json']

# getting the catalog.json
response = boto3.client('s3').get_object(Bucket=bucket, Key='collection02/catalog.json', RequestPayer='requester')
jsondata = response['Body'].read().decode()
-----------------------
s3 = boto3.client('s3', aws_access_key_id=AWS_KEY_ID,
                  aws_secret_access_key=AWS_SECRET)

resources = boto3.resource('s3', aws_access_key_id=AWS_KEY_ID,
                           aws_secret_access_key=AWS_SECRET)
import rasterio as rio
from matplotlib.pyplot import imshow
from rasterio.session import AWSSession

aws_session = AWSSession(requester_pays=True)

cog = 's3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF'


with rio.Env(aws_session):
    with rio.open(cog) as src:
        profile = src.profile
        arr = src.read(1)
imshow(arr)
-----------------------
s3 = boto3.client('s3', aws_access_key_id=AWS_KEY_ID,
                  aws_secret_access_key=AWS_SECRET)

resources = boto3.resource('s3', aws_access_key_id=AWS_KEY_ID,
                           aws_secret_access_key=AWS_SECRET)
import rasterio as rio
from matplotlib.pyplot import imshow
from rasterio.session import AWSSession

aws_session = AWSSession(requester_pays=True)

cog = 's3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF'


with rio.Env(aws_session):
    with rio.open(cog) as src:
        profile = src.profile
        arr = src.read(1)
imshow(arr)

How to implement a resetting function for custom generator in c++?

zgenerator(zgenerator&& other) noexcept : coro{std::exchange(other.coro, {})} { }
zgenerator& operator=(zgenerator&& other) noexcept {
    std::swap(coro, other.coro);
    return *this;
}

How do I connect kqlmagic to more than one Log Analytics workspace at the same time?

workspace('<workspace-A>').SecurityEvent

| union workspace('<workspace-B>').SecurityEvent

How to display a 32-bit DIV result stored in DX:AX

MOV AX,[SI+18]
MOV DX,[SI+20]

Infinite scroll component using GraphQL and IntersectionObserver

import { Fragment, ReactElement, ReactNode, useEffect, useRef, useState } from "react";
import useIntersection from "../hooks/intersectionHook";

export default function InfiniteComponent(props: InfiniteComponentProps): ReactElement {
    const [wait, setWait] = useState(false);
    const ready = useRef(!wait);
    const [entry, setSentinel] = useIntersection();

    useEffect(() => {
        ready.current = !wait;
    }, [wait]);

    useEffect(() => {
        const fetchMore = async (): Promise<void> => {
            setWait(true);
            await props.onMore();
            setWait(false);
        };

        if (ready.current && entry?.isIntersecting) {
            fetchMore();
        }
    }, [entry, props]);

    return (
        <Fragment>
            {props.children}
            {props.next && !wait && <div ref={setSentinel}></div>}
        </Fragment>
    );
}

export interface InfiniteComponentProps {
    next?: boolean;
    onMore: () => Promise<unknown>;
    children: ReactNode;
}

Removing duplicates from python array

a = ["Hello","Huitahani","good","Hello","apple","donkey","zebra","apple"]
# don't convert to set as it can mess up the order
result = [] 
for item in a: 
    if item not in result: # check if there is already one in result
        result.append(item) 

print(result) # print the new list instead of the original list
print('Enter strings (end with DONE):')
input_list = []
while True:
    user_input = input()
    if user_input == 'DONE':
        break
    input_list.append(user_input)
-----------------------
a = ["Hello","Huitahani","good","Hello","apple","donkey","zebra","apple"]
# don't convert to set as it can mess up the order
result = [] 
for item in a: 
    if item not in result: # check if there is already one in result
        result.append(item) 

print(result) # print the new list instead of the original list
print('Enter strings (end with DONE):')
input_list = []
while True:
    user_input = input()
    if user_input == 'DONE':
        break
    input_list.append(user_input)
-----------------------
a = []
item = input("Enter string (end with DONE):")
while not item == "DONE" : 
    if item not in a: 
        a.append(item)
    item = input("Enter next string (end with DONE):")
print(a)

Is there a more efficient way in performing repeated tasks in my batch file?

:InstallPrompt targetname targetpath
cls
echo  INSTALLING ----- %~1
echo  CONTINUE? PRESS ANY KEY TO CONTINUE
Pause
start "" "D:\SCRIPT\SETUPS\%~2" || Exit /B 1
echo  RETURNING...
timeout /t 2 > nul
Exit /B 0

COMMUNITY DISCUSSIONS

Top Trending Discussions on sentinel
  • Find the alphabetically first String using Java
  • Redis sentinel node can not sync after failover
  • Redis sentinel HA on Kubernetes
  • Why when I execute my Java program does it not convert the first user input, but does every user input after?
  • Rasterio &quot; does not exist in the file system, and is not recognized as a supported dataset name.&quot;
  • How to implement a resetting function for custom generator in c++?
  • How do I connect kqlmagic to more than one Log Analytics workspace at the same time?
  • How to display a 32-bit DIV result stored in DX:AX
  • The redundancy of forward_iterator concept?
  • Infinite scroll component using GraphQL and IntersectionObserver
Top Trending Discussions on sentinel

QUESTION

Find the alphabetically first String using Java

Asked 2021-Jun-13 at 21:16

My professor asked me to create a solution for this code, and I cannot quite get a good output. He asked me a couple things:

  1. Ask the user to input a String value, the value "END", terminates the loop and the program and is not included in the calculation of Strings.

  2. In the end, you should output which of the Strings that the user inputted is the String that comes alphabetically first. So for ex: if the user inputs "aac" and "aab", the "aab" comes first.

  3. I have created the code, but at the end of the output it gives me the value "END" as the first alphabetically String for some reason, and I am kind of confused.

I do not know if the professor asked right or is it just me that doesn't understand it!

My code so far:

import java.util.Scanner;

public class Ush1_NOTDONE {
    public static void main(String[]args) {
        Scanner sc =  new Scanner(System.in);
        System.out.println("Type a String value, the value \"END\" terminates the code");
        String word = sc.nextLine();

        final String SENTINEL = "END";

        String firstString = null;
        do {
            if(!word.equals(SENTINEL)) {
                System.out.println("Type a String value, the value \"END\" terminates the code");
                word = sc.nextLine();

                if(firstString == null || word.compareTo(firstString)<0 ){
                    firstString = word;
            }

        }}while(!(word.equals(SENTINEL)));

        System.out.println("First alphabetically string is: " + firstString);
        
    }

}

ANSWER

Answered 2021-Jun-13 at 18:34

Try to avoid do-while for this. Instead, do assignment in the while condition (assignment in java returns a value).

public class HelloWorld{

     public static void main(String []args){
        String word;
        Scanner sc = new Scanner(System.in);
        String first = null;
        
        while(!(word = sc.nextLine()).equals("END")) {
            if(first == null || word.compareTo(first) < 0) {
                first = word;
            }
        }
        
        System.out.println(first);
     }
}

Source https://stackoverflow.com/questions/67960411

QUESTION

Redis sentinel node can not sync after failover

Asked 2021-Jun-13 at 07:24

We have setup Redis with sentinel high availability using 3 nodes. Suppose fist node is master, when we reboot first node, failover happens and second node becomes master, until this point every thing is OK. But when fist node comes back it cannot sync with master and we saw that in its config no "masterauth" is set.
Here is the error log and Generated by CONFIG REWRITE config:

1182:S 29 May 2021 13:49:42.713 * Reconnecting to MASTER 192.168.1.2:6379 after failure
1182:S 29 May 2021 13:49:42.716 * MASTER <-> REPLICA sync started
1182:S 29 May 2021 13:49:42.716 * Non blocking connect for SYNC fired the event.
1182:S 29 May 2021 13:49:42.717 * Master replied to PING, replication can continue...
1182:S 29 May 2021 13:49:42.717 * (Non critical) Master does not understand REPLCONF listening-port: -NOAUTH Authentication required.
1182:S 29 May 2021 13:49:42.717 * (Non critical) Master does not understand REPLCONF capa: -NOAUTH Authentication required.
1182:S 29 May 2021 13:49:42.717 * Partial resynchronization not possible (no cached master)
1182:S 29 May 2021 13:49:42.718 # Unexpected reply to PSYNC from master: -NOAUTH Authentication required.
1182:S 29 May 2021 13:49:42.718 * Retrying with SYNC... 



# Generated by CONFIG REWRITE
save 3600 1
save 300 100
save 60 10000
user default on #eb5fbb922a75775721db681c49600c069cf686765eeebaa6e18fad195812140d ~* &* +@all
replicaof 192.168.1.2 6379

What is the problem?

Config Sample:

bind 127.0.0.1 -::1 192.168.1.3
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised systemd
pidfile "/var/run/redis_6379.pid"
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
rdb-del-sync-files no
dir "/"
replicaof 192.168.1.2 6379
masterauth "redis"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass "redis"
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4kb
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes

ANSWER

Answered 2021-Jun-13 at 07:24

For those who may run into same problem, problem was REDIS misconfiguration, after third deployment we carefully set parameters and no problem was found.

Source https://stackoverflow.com/questions/67749867

QUESTION

Redis sentinel HA on Kubernetes

Asked 2021-Jun-10 at 12:08

I am trying to have 1 redis master with 2 redis replicas tied to a 3 Quorum Sentinel on Kubernetes. I am very new to Kubernetes.

My initial plan was to have the master running on a pod tied to 1 Kubernetes SVC and the 2 replicas running on their own pods tied to another Kubernetes SVC. Finally, the 3 Sentinel pods will be tied to their own SVC. The replicas will be tied to the master SVC (because without svc, ip will change). The sentinel will also be configured and tied to master and replica SVCs. But I'm not sure if this is feasible because when master pod crashes, how will one of the replica pods move to the master SVC and become the master? Is that possible?

The second approach I had was to wrap redis pods in a replication controller and the same for sentinel as well. However, I'm not sure how to make one of the pods master and the others replicas with a replication controller.

Would any of the two approaches work? If not, is there a better design that I can adopt? Any leads would be appreciated.

ANSWER

Answered 2021-Jun-09 at 15:49

You can deploy Redis Sentinel using the Helm package manager and the Redis Helm Chart.
If you don't have Helm3 installed yet, you can use this documentation to install it.

I will provide a few explanations to illustrate how it works.


First we need to get the values.yaml file from the Redis Helm Chart to customize our installation:

$ wget https://raw.githubusercontent.com/bitnami/charts/master/bitnami/redis/values.yaml

We can configure a lot of parameters in the values.yaml file , but for demonstration purposes I only enabled Sentinel and set the redis password:
NOTE: For a list of parameters that can be configured during installation, see the Redis Helm Chart Parameters documentation.

# values.yaml

global:
  redis:
    password: redispassword
...
replica:
  replicaCount: 3
...
sentinel:
  enabled: true
...

Then we can deploy Redis using the configuration from the values.yaml file:
NOTE: It will deploy a three Pod cluster (one master and two slaves) managed by the StatefulSets with a sentinel container running inside each Pod.

$ helm install redis-sentinel bitnami/redis --values values.yaml

Be sure to carefully read the NOTES section of the chart installation output. It contains many useful information (e.g. how to connect to your database from outside the cluster)

After installation, check redis StatefulSet, Pods and Services (headless service can be used for internal access):

$ kubectl get pods -o wide
NAME                    READY   STATUS    RESTARTS   AGE     IP
redis-sentinel-node-0   2/2     Running   0          2m13s   10.4.2.21
redis-sentinel-node-1   2/2     Running   0          86s     10.4.0.10
redis-sentinel-node-2   2/2     Running   0          47s     10.4.1.10


$ kubectl get sts
NAME                  READY   AGE
redis-sentinel-node   3/3     2m41s

$ kubectl get svc
NAME                      TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)              AGE
redis-sentinel            ClusterIP   10.8.15.252   <none>        6379/TCP,26379/TCP   2m
redis-sentinel-headless   ClusterIP   None          <none>        6379/TCP,26379/TCP   2m

As you can see, each redis-sentinel-node Pod contains the redis and sentinel containers:

$ kubectl get pods redis-sentinel-node-0 -o jsonpath={.spec.containers[*].name}
redis sentinel

We can check the sentinel container logs to find out which redis-sentinel-node is the master:

$ kubectl logs -f redis-sentinel-node-0 sentinel
...
1:X 09 Jun 2021 09:52:01.017 # Configuration loaded
1:X 09 Jun 2021 09:52:01.019 * monotonic clock: POSIX clock_gettime
1:X 09 Jun 2021 09:52:01.019 * Running mode=sentinel, port=26379.
1:X 09 Jun 2021 09:52:01.026 # Sentinel ID is 1bad9439401e44e749e2bf5868ad9ec7787e914e
1:X 09 Jun 2021 09:52:01.026 # +monitor master mymaster 10.4.2.21 6379 quorum 2
...
1:X 09 Jun 2021 09:53:21.429 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.2.21 6379
1:X 09 Jun 2021 09:53:21.435 * +slave slave 10.4.1.10:6379 10.4.1.10 6379 @ mymaster 10.4.2.21 6379
...

As you can see from the logs above, the redis-sentinel-node-0 Pod is the master and the redis-sentinel-node-1 & redis-sentinel-node-2 Pods are slaves.

For testing, let's delete the master and check if sentinel will switch the master role to one of the slaves:

    $ kubectl delete pod redis-sentinel-node-0
    pod "redis-sentinel-node-0" deleted
    
    $ kubectl logs -f redis-sentinel-node-1 sentinel
    ...                                                                                           
    1:X 09 Jun 2021 09:55:20.902 # Executing user requested FAILOVER of 'mymaster'
    ...
    1:X 09 Jun 2021 09:55:22.666 # +switch-master mymaster 10.4.2.21 6379 10.4.1.10 6379
    ...
    1:X 09 Jun 2021 09:55:50.626 * +slave slave 10.4.0.10:6379 10.4.0.10 6379 @ mymaster 10.4.1.10 6379
    1:X 09 Jun 2021 09:55:50.632 * +slave slave 10.4.2.22:6379 10.4.2.22 6379 @ mymaster 10.4.1.10 6379

A new master (redis-sentinel-node-2 10.4.1.10) has been selected, so everything works as expected.

Additionally, we can display more information by connecting to one of the Redis nodes:

$ kubectl run --namespace default redis-client --restart='Never' --env REDIS_PASSWORD=redispassword --image docker.io/bitnami/redis:6.2.1-debian-10-r47 --command -- sleep infinity
pod/redis-client created
$ kubectl exec --tty -i redis-client --namespace default -- bash
I have no name!@redis-client:/$ redis-cli -h redis-sentinel-node-1.redis-sentinel-headless -p 6379 -a $REDIS_PASSWORD
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
redis-sentinel-node-1.redis-sentinel-headless:6379> info replication
# Replication
role:slave
master_host:10.4.1.10
master_port:6379
master_link_status:up
...

Source https://stackoverflow.com/questions/67886898

QUESTION

Why when I execute my Java program does it not convert the first user input, but does every user input after?

Asked 2021-Jun-09 at 04:15

I'm trying to write a java program for currency conversion as a class assignment. My code is working almost exactly the way I would like it to. When executed, it will ask for the user to input the Japanese Yen to US Dollar exchange rate. Enter any number and that works like it should.

However, it will prompt the user next to enter the amount of US dollars they want to convert to Yen. Again, the idea is to enter any number that is > 0 because if the user enters 0 the sentinel value will force a quit and build success message. When you enter a number and click 'Enter,' it just shows a blank line and does not make the conversion like I want it to.

But if you enter a number on that next blank line then it makes the conversion! You can even type in the numbers with spaces: 10 20 50 100... it will convert all of them on separate lines.

I'm just trying to figure out how to get rid of that first black line it gives and go straight into the conversions... or some other workaround.

Here is my code:

// Import scanner Object
import java.util.Scanner;
// Import text Object for formatting
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class CurrencyConversion {
    public static void main (String [] args) 
    {
        // Identify Scanner 
        Scanner input = new Scanner(System.in);
        
        // Declare variables
        double USDtoJPY; //JPY stands for Japanese Yen
        double USD;// USD stands for US Dollar
        int count = 0;
        
        // Formatting input
        DecimalFormat f = new DecimalFormat ("#,###.##");
        
        // Ask user to input exchange rate from JPY to USD
        System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
        USDtoJPY = input.nextDouble();
        
        // Ask user to input how many USD dollars they want to convert
        System.out.println("Enter amount in USD to convert: (0 to Quit)"); 
        USD = input.nextDouble();
        
        // Process Data until sentinel is entered
        while (USD != 0)
        {
            USD = input.nextDouble();
                count++;
        
            if (count > 0)
            {
                double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
                System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
            }
            else
            {
                System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
            }
        }
    } 
}


// Why do I have to input something to get it to start the loop? 

ANSWER

Answered 2021-Jun-09 at 04:07

You should move the USD = input.nextDouble(); inside of the while (USD != 0) loop to the end of the loop. Currently you are taking two inputs before the first output. If you move it to the end it works as expected.

// Import scanner Object
import java.util.Scanner;
// Import text Object for formatting
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class CurrencyConversion {
    public static void main (String [] args) 
    {
        // Identify Scanner 
        Scanner input = new Scanner(System.in);
        
        // Declare variables
        double USDtoJPY; //JPY stands for Japanese Yen
        double USD;// USD stands for US Dollar
        int count = 0;
        
        // Formatting input
        DecimalFormat f = new DecimalFormat ("#,###.##");
        
        // Ask user to input exchange rate from JPY to USD
        System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
        USDtoJPY = input.nextDouble();
        
        // Ask user to input how many USD dollars they want to convert
        System.out.println("Enter amount in USD to convert: (0 to Quit)"); 
        USD = input.nextDouble();
        
        // Process Data until sentinel is entered
        while (USD != 0)
        {
            count++;
        
            if (count > 0)
            {
                double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
                System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
            }
            else
            {
                System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
            }
            USD = input.nextDouble(); // move this here
        }
    } 
}

Or better yet, you can use a do while instead and have input only within the loop:

import java.util.Scanner;
import java.text.DecimalFormat;
/**
 *
 * @author dcraw
 */
public class DummyClass {
  public static void main (String [] args)
  {
    // Identify Scanner
    Scanner input = new Scanner(System.in);

    // Declare variables
    double USDtoJPY; //JPY stands for Japanese Yen
    double USD;// USD stands for US Dollar

    // Formatting input
    DecimalFormat f = new DecimalFormat ("#,###.##");

    // Ask user to input exchange rate from JPY to USD
    System.out.println("What is today's price in JPY for 1 USD?"); // As of 6/6/2021, 1 USD = 109.55 JPY
    USDtoJPY = input.nextDouble();

    // Ask user to input how many USD dollars they want to convert
    System.out.println("Enter amount in USD to convert: (0 to Quit)");

    // Process Data until sentinel is entered
    do {
      USD = input.nextDouble();

      if (USD > 0)
      {
        double JPY = USDtoJPY * USD; // Perform calculation with exchange rate
        System.out.println("Your " + USD + " dollars is converted to " + f.format(JPY) + " yen");
      }
      else
      {
        System.out.println("Incorrect Data"); // If data is entered incorrectly print Incorrect data
      }
    } while (USD != 0);
  }
}

Source https://stackoverflow.com/questions/67897348

QUESTION

Rasterio &quot; does not exist in the file system, and is not recognized as a supported dataset name.&quot;

Asked 2021-Jun-03 at 14:53

Following this tutorial: https://www.usgs.gov/media/files/landsat-cloud-direct-access-requester-pays-tutorial

import boto3
import rasterio as rio
from matplotlib.pyplot import imshow
from rasterio.session import AWSSession

s3 = boto3.client('s3', aws_access_key_id=AWS_KEY_ID,
                  aws_secret_access_key=AWS_SECRET)

resources = boto3.resource('s3', aws_access_key_id=AWS_KEY_ID,
                           aws_secret_access_key=AWS_SECRET)

aws_session = AWSSession(boto3.Session())

cog = 's3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF'

with rio.Env(aws_session):
    with rio.open(cog) as src:
        profile = src.profile
        arr = src.read(1)
imshow(arr)

I get the below error:

rasterio.errors.RasterioIOError: '/vsis3/usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/LC08_L2SP_026027_20200827_20200906_02_T1_SR_B2.TIF' does not exist in the file system, and is not recognized as a supported dataset name.
In AWS CloudShell if I run: ``` aws s3 ls s3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/ ```

I get:

An error occurred (AccessDenied) when calling the ListObjectsV2 operation: Access Denied

I ran the cloudshell commands in an EC2 instance, same errors.

I needed to specify that I am requester its right in the documentation, this works:

aws s3 ls s3://usgs-landsat/collection02/level-2/standard/oli-tirs/2020/026/027/LC08_L2SP_026027_20200827_20200906_02_T1/ --request-payer requ
ester

Using boto3 still doesn't work.

I have admin permissions on the user I was running boto3 with. Got the same error in CloudShell as both the boto user and root. I have used the access key and secret key before and it works fine for downloading from the "landsat-pds" bucket (only has L8 images) and the "sentinel-s2-l1c" bucket. Only seems to be an issue with the "usgs-landsat" bucket (https://registry.opendata.aws/usgs-landsat/)

Also tried accessing the usgs-landsat bucket with s3.list_objects:

landsat = resources.Bucket("usgs-landsat")
all_objects = s3.list_objects(Bucket = 'usgs-landsat')

Get a similar error:

botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied

After looking at other solutions some users found:

os.environ["AWS_REQUEST_PAYER"] = "requester"
os.environ["CURL_CA_BUNDLE"] = "/etc/ssl/certs/ca-certificates.crt"

To fix their issue, it hasn't worked for me.

ANSWER

Answered 2021-Jun-03 at 01:54

This worked for me

s3sr = boto3.resource('s3')
bucket='usgs-landsat'
prefix = 'collection02/'
keys_list = []
paginator = s3sr.meta.client.get_paginator('list_objects_v2')
for page in  paginator.paginate(Bucket=bucket, Prefix=prefix, Delimiter='/', RequestPayer='requester'):
    keys = [content['Key'] for content in page.get('Contents')]
    keys_list.extend(keys)
len(keys_list)

# keys_list 
['collection02/catalog.json',
 'collection02/landsat-c2l1.json',
 'collection02/landsat-c2l2-sr.json',
 'collection02/landsat-c2l2-st.json',
 'collection02/landsat-c2l2alb-bt.json',
 'collection02/landsat-c2l2alb-sr.json',
 'collection02/landsat-c2l2alb-st.json',
 'collection02/landsat-c2l2alb-ta.json']

# getting the catalog.json
response = boto3.client('s3').get_object(Bucket=bucket, Key='collection02/catalog.json', RequestPayer='requester')
jsondata = response['Body'].read().decode()

Source https://stackoverflow.com/questions/67812512

QUESTION

How to implement a resetting function for custom generator in c++?

Asked 2021-Jun-03 at 10:51

I've created a class called zgenerator:

template <typename T>
class zgenerator {
  public:
    class promise_type;
    using handle = std::coroutine_handle<promise_type>;

  private:
    handle coro;
    explicit zgenerator(handle h) : coro{h} {}

  public:
    // default constructor
    zgenerator() noexcept : coro{nullptr} {}
    // move constructor and assignment
    zgenerator(zgenerator&& other) noexcept : coro{std::move(other.coro)} { }
    zgenerator& operator=(zgenerator&& other) noexcept {
        coro = std::move(other.coro);
        return *this;
    }
    // deleting copy constructor and assignment
    zgenerator(const zgenerator&) = delete;
    zgenerator& operator=(const zgenerator&) = delete;
    // destructor
    ~zgenerator() { if (coro) coro.destroy(); }

    // promise type
    class promise_type {
      public:
        using value_type = std::remove_reference_t<T>;
        using reference_type = std::conditional_t<std::is_reference_v<T>, T, T&>;
        using pointer_type = value_type*;

      private:
        pointer_type m_value;
        std::exception_ptr m_except;

      public:
        zgenerator get_return_object() noexcept {
            return zgenerator{handle::from_promise(*this)};
        }

        static auto get_return_object_on_allocation_failure() {
            return zgenerator{nullptr};
        }

        std::suspend_always initial_suspend() const noexcept { return {}; }
        std::suspend_always final_suspend() const noexcept { return {}; }

        // no 'co_await'
        template <typename T1> std::suspend_never await_transform(T1&&) = delete;

        std::suspend_always yield_value(std::remove_reference_t<T>& value) noexcept
            requires std::is_rvalue_reference_v<T>
        {
            m_value = std::addressof(value);
            return {};
        }

        std::suspend_always yield_value(std::remove_reference_t<T>&& value) noexcept {
            m_value = std::addressof(value);
            return {};
        }

        void unhandled_exception() {
            m_except = std::current_exception();
        }

        void rethrow_if_exception() {
            if (m_except)
                std::rethrow_exception(m_except);
        }

        void return_void() {}

        reference_type value() const noexcept {
            return static_cast<reference_type>(*m_value);
        }

    };

    // sentinel
    struct sentinel {};

    // iterator
    class iterator {
      private:
        handle m_coro;
      public:
        using value_type = typename promise_type::value_type;
        using reference  = typename promise_type::reference_type;
        using pointer    = typename promise_type::pointer_type;
        using difference_type = std::ptrdiff_t;
        using iterator_category = std::input_iterator_tag;

        iterator() noexcept : m_coro{nullptr} {}
        explicit iterator(handle other) noexcept : m_coro{other} {}

        friend bool operator==(const iterator& it, sentinel) noexcept {
            return !it.m_coro || it.m_coro.done();
        }

        friend bool operator==(sentinel s, const iterator& it) noexcept {
            return (it == s);
        }

        iterator& operator++() {
            m_coro.resume();
            if (m_coro.done()) {
                m_coro.promise().rethrow_if_exception();
            }
            return *this;
        }

        void operator++(int) {
            (void) this->operator++();
        }

        reference operator*() const noexcept {
            return m_coro.promise().value();
        }

        pointer operator->() const noexcept {
            return std::addressof(this->operator*());
        }
    };

    // iterators
    iterator begin() {
        if (coro) {
            coro.resume();
            if (coro.done()) {
                coro.promise().rethrow_if_exception();
            }
        }
        return iterator{coro};
    }

    sentinel end() noexcept {
        return sentinel{};
    }

    void swap(zgenerator& other) noexcept {
        using std::swap;
        swap(coro, other.coro);
    }

    // manual yielding
    T value() { return coro.promise().value(); }
    bool next() {
        if (coro) {
            coro.resume();
            return !coro.done();
        } else
            return false;
    }
    bool is_done() { return coro.done(); }
};

This is the application:

auto generate_num = [] -> zgenerator<int> {
    co_yield 1;
    co_yield 3;
    co_yield 10;
    co_yield -1;
};
auto it = generate_num();

// Used in for-loop:
for (const auto& i : it)
    std::cout << i << ' ';
std::cout << '\n';

Output:

1 3 10 -1

I want to reset the object back into the first state. When I tried to reassign a new generator object from it, it throws a runtime error:

it = generate_num();

Expectation:

// reset:
it.reset();
it.next();
while (!it.is_done()) {
    std::cout << it.value() << ' ';
    it.next();
}
// now printing twice if we include this.

How could I implement a resetting function in my generator?

ANSWER

Answered 2021-Jun-03 at 10:51

Your move constructor and assignment need to ensure other.coro doesn't still point to what it used to, otherwise you double-destroy it.

zgenerator(zgenerator&& other) noexcept : coro{std::exchange(other.coro, {})} { }
zgenerator& operator=(zgenerator&& other) noexcept {
    std::swap(coro, other.coro);
    return *this;
}

Source https://stackoverflow.com/questions/67819941

QUESTION

How do I connect kqlmagic to more than one Log Analytics workspace at the same time?

Asked 2021-Jun-02 at 14:49

In my Jupyter notebook, I want to run the same KQL query against different Sentinel workspaces and compare the results as data frames. Is there an easy way to have multiple workspace connections at the same time or would I need to reconnect and query each workspace individually every time I change my KQL query?

ANSWER

Answered 2021-Jun-02 at 11:33

See if cross-workspace queries satisfy your requirements. And a bit more documentation here. Cross-workspace queries are for exactly you describe. You use a union operator to link both - similar to how you would link two tables using union.

Snipped from the article:

workspace('<workspace-A>').SecurityEvent

| union workspace('<workspace-B>').SecurityEvent

Source https://stackoverflow.com/questions/67802643

QUESTION

How to display a 32-bit DIV result stored in DX:AX

Asked 2021-Jun-02 at 02:58

I wrote this code to display a current value after some calculations. But the program gives wrong output when it should gave decimal 10 result it gives 13107 result and i cant find the reason why. Before this label what I did was basically getting inputs from the user and storing those values at si register.

islem: 

  MOV AX,[SI+14]
  MOV BX,[SI+10]
  MOV CX,[SI+2]
  
  SUB AX,BX
  SUB AX,CX
  
  MOV BX,[SI+8]
  
  MOV [SI+16],AX
  
  MOV DX,00H
  MOV AX,[SI+16]
  DIV BX
  
  
  
  MOV [SI+18],OFFSET IE
  
  MOV [SI+18],AX
  MOV [SI+20],DX
  
  CALL NEWLINE
  
  mov dx, offset Ie_msg
  mov ah,9
  int 21h
  
  MOV AX,[SI+18]
  MOV DX,[SI+20]
  

  
    mov     bx,10          ;CONST
    push    bx             ;Sentinel
a: mov     cx,ax          ;Temporarily store LowDividend in CX
    mov     ax,dx          ;First divide the HighDividend
    xor     dx,dx          ;Setup for division DX:AX / BX
    div     bx             ; -> AX is HighQuotient, Remainder is re-used
    xchg    ax,cx          ;Temporarily move it to CX restoring LowDividend
    div     bx             ; -> AX is LowQuotient, Remainder DX=[0,9]
    push    dx             ;(1) Save remainder for now
    mov     dx,cx          ;Build true 32-bit quotient in DX:AX
    or      cx,ax          ;Is the true 32-bit quotient zero?
    jnz     a             ;No, use as next dividend
    pop     dx             ;(1a) First pop (Is digit for sure)
b: add     dl,"0"         ;Turn into character [0,9] -> ["0","9"]
    mov     ah,02h         ;DOS.DisplayCharacter
    int     21h            ; -> AL
    pop     dx             ;(1b) All remaining pops
    cmp     dx,bx          ;Was it the sentinel?
    jb      b             ;Not yet
  



ret

ANSWER

Answered 2021-Jun-01 at 21:39
MOV AX,[SI+18]
MOV DX,[SI+20]

The result of your calculation came from a division (div bx). The quotient is held in the AX register only. The DX register contains the remainder from the division.

Just load AX with mov ax, [si+18] and then zero DX with xor dx, dx.
Hereafter you can run my conversion code...

Source https://stackoverflow.com/questions/67796211

QUESTION

The redundancy of forward_iterator concept?

Asked 2021-May-31 at 14:24

In [iterator.concept.forward], std::forward_iterator is defined as:

template<class I>
  concept forward_­iterator =
    input_­iterator<I> &&
    derived_­from<ITER_CONCEPT(I), forward_iterator_tag> &&
    incrementable<I> &&
    sentinel_­for<I, I>;

and std::sentinel_for<I, I> is defined as:

template<class S, class I>
  concept sentinel_­for =
    semiregular<S> &&
    input_­or_­output_­iterator<I> &&
    weakly-equality-comparable-with<S, I>;

which seems to be redundant in std::forward_iterator's requirement, since input_iterator already models input_or_output_iterator, and incrementable is defined as:

template<class I>
  concept incrementable =
    regular<I> &&
    weakly_­incrementable<I> &&
    requires(I i) {
      { i++ } -> same_­as<I>;
    };

which models regular which models semiregular and equality_­comparable which models weakly-equality-comparable-with<I, I>.

Why does the standard need to add a constraint that seems redundant here, and what are the considerations behind this?

ANSWER

Answered 2021-May-31 at 13:21

forward_­iterator needs the semantic requirements of sentinel_for. Those are not implied by either regular or equality_comparable.

Source https://stackoverflow.com/questions/67774510

QUESTION

Infinite scroll component using GraphQL and IntersectionObserver

Asked 2021-May-30 at 11:18

I have few experience with React and I am trying to do Infinite scroll using GraphQL and IntersectionObserver, all work but I am getting the twice the results I request for. I guess it's from a double render, one from @apollo/client fetchMore and other from the IntersectionObserver hook but I don't quite understand it and I don't know how to fix it.

The IntersectionObserver hook:

import { useCallback, useRef, useState } from "react";

export default function useIntersection(options?: IntersectionObserverInit): IntersectionHook {
    const [entry, setEntry] = useState<IntersectionObserverEntry>();
    const observer = useRef<IntersectionObserver>();
    const target = useRef<Element | null>(null);

    const setSentinel = useCallback<IntersectionHook[0]>(
        (sentinel) => {
            if (!observer.current) {
                observer.current = new IntersectionObserver((entries) => setEntry(entries[0]), options);
            }

            if (target.current) {
                observer.current.unobserve(target.current);
            }

            target.current = sentinel;

            if (target.current) {
                observer.current.observe(target.current);
            }
        },
        [options],
    );

    return [setSentinel, entry];
}

type IntersectionHook = [(sentinel: Element | null) => void, IntersectionObserverEntry | undefined];

The component using the hook:

import { Fragment, ReactElement, ReactNode, useEffect } from "react";
import useIntersection from "../hooks/intersectionHook";

export default function InfiniteComponent(props: InfiniteComponentProps): ReactElement {
    const [setSentinel, entry] = useIntersection();

    useEffect(() => {
        if (entry?.isIntersecting) {
            props.onNext();
        }
    }, [props, entry]);

    return (
        <Fragment>
            {props.children}
            {props.next && <div ref={setSentinel}></div>}
        </Fragment>
    );
}

export interface InfiniteComponentProps {
    next?: boolean;
    onNext: () => Promise<unknown>;
    children: ReactNode;
}

The page using the component:

export default function IndexArtist(): ReactElement | null {
    const { loading, error, data, fetchMore } = useQuery<IndexArtistData, IndexArtistVars>(INDEX_ARTIST, {
        variables: { limit: 3 },
    });

    if (loading) {
        return null;
    }

    if (error) {
        return <Redirect to="/error" />;
    }

    if (!data?.artists.nodes.length) {
        return <Redirect to="/error" />;
    }

    return (
        <BoxElement $variant="page">
            <InfiniteComponent
                next={data.artists.page.next}
                onNext={async () => fetchMore({ variables: { cursor: data.artists.page.cursor } })}
            >
                {/* The code to render */}
            </InfiniteComponent>
        </BoxElement>

With the above code, I request 3 results and I get 3 results when loading the page but when I scroll down until the sentinel of the IntersectionObserver hook to fetch more results I get 6 results (first I get 3 results but shortly after, a few miliseconds after, I get othe 3 results).

ANSWER

Answered 2021-May-30 at 11:18

I still open to suggestions. The next solution does not seems the more elegant, but it is the only I found.

The component using the hook:

import { Fragment, ReactElement, ReactNode, useEffect, useRef, useState } from "react";
import useIntersection from "../hooks/intersectionHook";

export default function InfiniteComponent(props: InfiniteComponentProps): ReactElement {
    const [wait, setWait] = useState(false);
    const ready = useRef(!wait);
    const [entry, setSentinel] = useIntersection();

    useEffect(() => {
        ready.current = !wait;
    }, [wait]);

    useEffect(() => {
        const fetchMore = async (): Promise<void> => {
            setWait(true);
            await props.onMore();
            setWait(false);
        };

        if (ready.current && entry?.isIntersecting) {
            fetchMore();
        }
    }, [entry, props]);

    return (
        <Fragment>
            {props.children}
            {props.next && !wait && <div ref={setSentinel}></div>}
        </Fragment>
    );
}

export interface InfiniteComponentProps {
    next?: boolean;
    onMore: () => Promise<unknown>;
    children: ReactNode;
}

Source https://stackoverflow.com/questions/66876777

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

VULNERABILITIES

HashiCorp Sentinel up to 0.10.1 incorrectly parsed negation in certain policy expressions. Fixed in 0.10.2.
In NetIQ Sentinel before 8.1.x, a Sentinel user is logged into the Sentinel Web Interface. After performing some tasks within Sentinel the user does not log out but does go idle for a period of time. This in turn causes the interface to timeout so that it requires the user to re-authenticate. If another user is passing by and decides to login, their credentials are accepted. While The user does not inherit any of the other users privileges, they are able to view the previous screen. In this case it is possible that the user can see another users events or configuration information for whatever view is currently showing.

INSTALL sentinel

Clone SAMOA fork for Sentinel. Add twitter4j.properties file in the root of the project. More info at Twitter 4J's Documentation on Generic properties.

SUPPORT

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

Implement sentinel faster with kandi.

  • Use the support, quality, security, license, reuse scores and reviewed functions to confirm the fit for your project.
  • Use the, Q & A, Installation and Support guides to implement faster.

Discover Millions of Libraries and
Pre-built Use Cases on kandi